Revision 57157
Added by Enrico Ottonello over 4 years ago
SolrIndexDocument.java | ||
---|---|---|
4 | 4 |
import java.util.HashMap; |
5 | 5 |
import java.util.Map; |
6 | 6 |
|
7 |
import eu.dnetlib.clients.index.model.Any.ValueType; |
|
8 |
import eu.dnetlib.clients.index.model.document.AbstractIndexDocument; |
|
9 | 7 |
import org.apache.solr.common.SolrInputDocument; |
10 | 8 |
import org.apache.solr.common.SolrInputField; |
11 | 9 |
|
10 |
import eu.dnetlib.clients.index.model.Any.ValueType; |
|
11 |
import eu.dnetlib.clients.index.model.document.AbstractIndexDocument; |
|
12 |
|
|
12 | 13 |
// TODO: Auto-generated Javadoc |
13 | 14 |
|
14 | 15 |
/** |
... | ... | |
19 | 20 |
/** |
20 | 21 |
* Instantiates a new solr index document. |
21 | 22 |
* |
22 |
* @param schema the schema |
|
23 |
* @param dsId the ds id |
|
23 |
* @param schema |
|
24 |
* the schema |
|
25 |
* @param dsId |
|
26 |
* the ds id |
|
24 | 27 |
*/ |
25 | 28 |
public SolrIndexDocument(final Map<String, ValueType> schema, final String dsId) { |
26 | 29 |
super(schema, dsId); |
... | ... | |
29 | 32 |
/** |
30 | 33 |
* Instantiates a new solr index document. |
31 | 34 |
* |
32 |
* @param schema the schema |
|
33 |
* @param dsId the ds id |
|
34 |
* @param solrDocument the solr document |
|
35 |
* @param schema |
|
36 |
* the schema |
|
37 |
* @param dsId |
|
38 |
* the ds id |
|
39 |
* @param solrDocument |
|
40 |
* the solr document |
|
35 | 41 |
*/ |
36 | 42 |
public SolrIndexDocument(final Map<String, ValueType> schema, final String dsId, final SolrInputDocument solrDocument) { |
37 | 43 |
super(schema, dsId); |
... | ... | |
41 | 47 |
/** |
42 | 48 |
* Adds the fields. |
43 | 49 |
* |
44 |
* @param solrDocument the solr document |
|
50 |
* @param solrDocument |
|
51 |
* the solr document |
|
45 | 52 |
*/ |
46 | 53 |
private void addFields(final SolrInputDocument solrDocument) { |
47 | 54 |
for (String name : solrDocument.getFieldNames()) { |
48 | 55 |
Collection<Object> fieldValues = solrDocument.getFieldValues(name); |
49 |
if (fieldValues.size() > 1) |
|
56 |
if (fieldValues.size() > 1) {
|
|
50 | 57 |
addField(name, fieldValues); |
51 |
else if (fieldValues.size() == 1)
|
|
58 |
} else if (fieldValues.size() == 1) {
|
|
52 | 59 |
addField(name, fieldValues.iterator().next()); |
60 |
} |
|
53 | 61 |
} |
54 | 62 |
} |
55 | 63 |
|
56 | 64 |
/** |
57 | 65 |
* Sets the content. |
58 | 66 |
* |
59 |
* @param solrDocument the new content |
|
67 |
* @param solrDocument |
|
68 |
* the new content |
|
60 | 69 |
*/ |
61 | 70 |
public void setContent(final SolrInputDocument solrDocument) { |
62 | 71 |
addFields(solrDocument); |
... | ... | |
69 | 78 |
*/ |
70 | 79 |
public SolrInputDocument getSolrDocument() { |
71 | 80 |
|
72 |
Map<String, SolrInputField> data = new HashMap<String, SolrInputField>();
|
|
81 |
Map<String, SolrInputField> data = new HashMap<>(); |
|
73 | 82 |
for (String key : fields.keySet()) { |
74 | 83 |
SolrInputField solrField = new SolrInputField(key); |
75 | 84 |
for (Object o : fields.get(key)) { |
76 |
solrField.addValue(o, 1.0f);
|
|
85 |
solrField.addValue(o); |
|
77 | 86 |
} |
78 | 87 |
data.put(key, solrField); |
79 | 88 |
} |
Also available in: Unified diff
solr 772 integration