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.content;
20
21 import java.io.IOException;
22 import java.util.Collections;
23 import java.util.List;
24
25 import org.apache.solr.client.solrj.SolrClient;
26 import org.apache.solr.client.solrj.SolrServerException;
27 import org.apache.solr.common.SolrInputDocument;
28 import org.mycore.common.content.MCRContent;
29 import org.mycore.datamodel.metadata.MCRObjectID;
30 import org.mycore.solr.MCRSolrClientFactory;
31 import org.mycore.solr.index.MCRSolrIndexHandler;
32 import org.mycore.solr.index.document.MCRSolrInputDocumentFactory;
33 import org.mycore.solr.index.handlers.MCRSolrAbstractIndexHandler;
34 import org.mycore.solr.index.handlers.document.MCRSolrInputDocumentHandler;
35 import org.mycore.solr.index.statistic.MCRSolrIndexStatistic;
36 import org.mycore.solr.index.statistic.MCRSolrIndexStatisticCollector;
37 import org.xml.sax.SAXException;
38
39
40
41
42
43 public class MCRSolrMCRContentIndexHandler extends MCRSolrAbstractIndexHandler {
44
45 MCRObjectID id;
46
47 MCRContent content;
48
49 private SolrInputDocument document;
50
51 public MCRSolrMCRContentIndexHandler(MCRObjectID id, MCRContent content) {
52 this(id, content, MCRSolrClientFactory.getMainSolrClient());
53 }
54
55 public MCRSolrMCRContentIndexHandler(MCRObjectID id, MCRContent content, SolrClient solrClient) {
56 super(solrClient);
57 this.id = id;
58 this.content = content;
59 }
60
61 @Override
62 public MCRSolrIndexStatistic getStatistic() {
63 return MCRSolrIndexStatisticCollector.DOCUMENTS;
64 }
65
66
67
68
69 @Override
70 public void index() throws IOException, SolrServerException {
71 try {
72 this.document = MCRSolrInputDocumentFactory.getInstance().getDocument(id, content);
73 } catch (SAXException e) {
74 throw new IOException(e);
75 }
76 }
77
78 @Override
79 public List<MCRSolrIndexHandler> getSubHandlers() {
80 MCRSolrIndexHandler mcrSolrIndexHandler = new MCRSolrInputDocumentHandler(document, getSolrClient());
81 mcrSolrIndexHandler.setCommitWithin(getCommitWithin());
82 return Collections.singletonList(mcrSolrIndexHandler);
83 }
84
85 @Override
86 public int getDocuments() {
87 return 0;
88 }
89
90 @Override
91 public String toString() {
92 return "index " + id;
93 }
94
95 }