1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.solr.index.handlers.document;
20
21 import java.io.IOException;
22
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
25 import org.apache.solr.client.solrj.SolrClient;
26 import org.apache.solr.client.solrj.SolrServerException;
27 import org.apache.solr.client.solrj.request.UpdateRequest;
28 import org.apache.solr.common.SolrInputDocument;
29 import org.mycore.solr.MCRSolrConstants;
30 import org.mycore.solr.MCRSolrUtils;
31 import org.mycore.solr.index.MCRSolrIndexer;
32 import org.mycore.solr.index.handlers.MCRSolrAbstractIndexHandler;
33 import org.mycore.solr.index.statistic.MCRSolrIndexStatistic;
34 import org.mycore.solr.index.statistic.MCRSolrIndexStatisticCollector;
35
36
37
38
39
40 public class MCRSolrInputDocumentHandler extends MCRSolrAbstractIndexHandler {
41
42 private static Logger LOGGER = LogManager.getLogger(MCRSolrInputDocumentHandler.class);
43
44 SolrInputDocument document;
45
46 public MCRSolrInputDocumentHandler(SolrInputDocument document) {
47 super();
48 this.document = document;
49 }
50
51 public MCRSolrInputDocumentHandler(SolrInputDocument document, SolrClient solrClient) {
52 super(solrClient);
53 this.document = document;
54 }
55
56
57
58
59 @Override
60 public void index() throws IOException, SolrServerException {
61 String id = String.valueOf(document.getFieldValue("id"));
62 SolrClient solrClient = getSolrClient();
63 LOGGER.info("Sending {} to SOLR...", id);
64 if (MCRSolrUtils.useNestedDocuments()) {
65 MCRSolrIndexer.deleteById(solrClient, id);
66 }
67 UpdateRequest updateRequest = getUpdateRequest(MCRSolrConstants.SOLR_UPDATE_PATH);
68 updateRequest.add(document);
69 updateRequest.process(solrClient);
70 }
71
72
73
74
75 @Override
76 public MCRSolrIndexStatistic getStatistic() {
77 return MCRSolrIndexStatisticCollector.DOCUMENTS;
78 }
79
80 @Override
81 public String toString() {
82 return "index " + document.getFieldValue("id");
83 }
84
85 }