Scenario
I am sending query to a middle proxy layer which talks with remote Solr server, import the received documents into Local Solr server.
There are different ways to put data into Local Solr server.
1. Use core.getUpdateHandler(), we can add SolrInputDocuemt, delete by id or query.
2. We can use SolrRequestHandler like below:
SolrRequestHandler updateHandler = core.getRequestHandler("/update");
SolrQueryRequest req = new LocalSolrQueryRequest(core,solrParams);
updateHandler.handleRequest(req, solrQueryRsp);
Be sure to close the created SolrQueryRequest. Please refer to.
Compared with method 2, method 1 is better, as this pass the phrases- 1: Create a XML or JSON documents playload. 2: Parse the playload. 3: Create a SolrInputDocuemt from playload.
But with method 1, we can 't tell it to execute one processor chain.
Solution
If we want to tell Solr to execute one processor chain, before import data, we can get one UpdateRequestProcessorChain, create a processor, and use the processor to add a new SolrInputDocuemt.
I am sending query to a middle proxy layer which talks with remote Solr server, import the received documents into Local Solr server.
There are different ways to put data into Local Solr server.
1. Use core.getUpdateHandler(), we can add SolrInputDocuemt, delete by id or query.
2. We can use SolrRequestHandler like below:
SolrRequestHandler updateHandler = core.getRequestHandler("/update");
SolrQueryRequest req = new LocalSolrQueryRequest(core,solrParams);
updateHandler.handleRequest(req, solrQueryRsp);
Be sure to close the created SolrQueryRequest. Please refer to.
Compared with method 2, method 1 is better, as this pass the phrases- 1: Create a XML or JSON documents playload. 2: Parse the playload. 3: Create a SolrInputDocuemt from playload.
But with method 1, we can 't tell it to execute one processor chain.
Solution
If we want to tell Solr to execute one processor chain, before import data, we can get one UpdateRequestProcessorChain, create a processor, and use the processor to add a new SolrInputDocuemt.
UpdateRequestProcessorChain updateChian = request.getCore().getUpdateProcessingChain("dedup"); UpdateRequestProcessor processor = updateChian.createProcessor(request,response); ddUpdateCommand command = new AddUpdateCommand(request); command.solrDoc = toSolrServerSolrDoc; processor.processAdd(command);The complete code looks like below
private static boolean importDocs(String remoteDocsStr, SolrQueryRequest request) throws IOException { Object obj = ObjectBuilder.fromJSON(remoteDocsStr); HashMap map = (HashMap) obj; HashMap responseMap = (HashMap) map.get("response"); Listlists = (List ) responseMap.get("docs"); UpdateRequestProcessorChain updateChian = request.getCore() .getUpdateProcessingChain("dedup"); for (HashMap docJsonMap : lists) { SolrInputDocument toSolrServerSolrDoc = convertToSolrDoc(docJsonMap); AddUpdateCommand command = new AddUpdateCommand(request); command.solrDoc = toSolrServerSolrDoc; SolrQueryResponse response = new SolrQueryResponse(); UpdateRequestProcessor processor = updateChian.createProcessor(request, response); processor.processAdd(command); } }