Project

General

Profile

1
package eu.dnetlib.functionality.index.model.util;
2

    
3
import java.util.Map;
4

    
5
import org.apache.solr.common.SolrInputDocument;
6

    
7
import eu.dnetlib.functionality.index.model.Any.ValueType;
8
import eu.dnetlib.functionality.index.model.document.AbstractIndexDocument;
9

    
10
/**
11
 * The Class SolrIndexDocument an implementation of the index document for SOLR.
12
 */
13
public class SolrIndexDocument extends AbstractIndexDocument {
14

    
15
	/**
16
	 * Instantiates a new solr index document.
17
	 * 
18
	 * @param schema
19
	 *            the schema
20
	 * @param dsId
21
	 *            the ds id
22
	 */
23
	public SolrIndexDocument(final Map<String, ValueType> schema, final String dsId) {
24
		super(schema, dsId);
25
	}
26

    
27
	/**
28
	 * Instantiates a new solr index document.
29
	 * 
30
	 * @param schema
31
	 *            the schema
32
	 * @param dsId
33
	 *            the ds id
34
	 * @param solrDocument
35
	 *            the solr document
36
	 */
37
	public SolrIndexDocument(final Map<String, ValueType> schema, final String dsId, final SolrInputDocument solrDocument) {
38
		super(schema, dsId);
39
		addFields(solrDocument);
40
	}
41

    
42
	/**
43
	 * Adds the fields.
44
	 * 
45
	 * @param solrDocument
46
	 *            the solr document
47
	 */
48
	private void addFields(final SolrInputDocument solrDocument) {
49
		for (String name : solrDocument.getFieldNames()) {
50
			Object fieldValue = solrDocument.getFieldValue(name);
51
			addField(name, fieldValue);
52
		}
53
	}
54

    
55
	/**
56
	 * Sets the content.
57
	 * 
58
	 * @param solrDocument
59
	 *            the new conten
60
	 */
61
	public void setContent(final SolrInputDocument solrDocument) {
62
		addFields(solrDocument);
63
	}
64
}
(2-2/2)