public static void addDoc(String doc, String updateRequestProcessorChain) throws Exception { Map<String, String[]> params = new HashMap<>(); MultiMapSolrParams mmparams = new MultiMapSolrParams(params); params.put(UpdateParams.UPDATE_CHAIN, new String[]{updateRequestProcessorChain}); SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) { }; UpdateRequestHandler handler = new UpdateRequestHandler(); handler.init(null); ArrayList<ContentStream> streams = new ArrayList<>(2); streams.add(new ContentStreamBase.StringStream(doc)); req.setContentStreams(streams); handler.handleRequestBody(req, new SolrQueryResponse()); req.close(); }
/** It is the users responsibility to close the request object when done with it. * This method does not set/clear SolrRequestInfo */ public SolrQueryResponse queryAndResponse(String handler, SolrQueryRequest req) throws Exception { try (SolrCore core = getCoreInc()) { SolrQueryResponse rsp = new SolrQueryResponse(); core.execute(core.getRequestHandler(handler), req, rsp); if (rsp.getException() != null) { throw rsp.getException(); } return rsp; } }
public SolrQueryResponse handleSuggestionResponseRequest(ReSearcherRequestContext ctx, ModifiableSolrParams params, String componentName, List<SearchComponent> components) throws Exception { params.set(componentName, "false"); SolrQueryRequest req = new SolrQueryRequestBase(ctx.getCore(), params) {}; SolrQueryResponse rsp = new SolrQueryResponse(); ResponseBuilder rb = new ResponseBuilder(req, rsp, components); try { handleSuggestionRequest(ctx, rb, components, false); } finally { req.close(); } return rsp; }
private void writeToCloud (SolrInputDocument solrDoc, String uri) { ArrayList<String> urls = xqueryComponent.getShardURLs(true); LoggerFactory.getLogger(getClass()).debug ("writing " + uri + " to cloud at " + urls); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = UpdateDocCommand.makeSolrRequest(core); ((ModifiableSolrParams)req.getParams()).add(ShardParams.SHARDS, urls.toArray(new String[urls.size()])); UpdateRequest updateReq = new UpdateRequest(); updateReq.add(solrDoc); UpdateDocCommand cmd = new UpdateDocCommand(req, solrDoc, null, uri); UpdateRequestProcessorChain updateChain = xqueryComponent.getCore().getUpdateProcessingChain("lux-update-chain"); try { UpdateRequestProcessor processor = updateChain.createProcessor(req, rsp); processor.processAdd(cmd); processor.finish(); } catch (IOException e) { throw new LuxException (e); } }
private void deleteCloud (DeleteUpdateCommand cmd) throws IOException { UpdateRequestProcessorChain updateChain = xqueryComponent.getCore().getUpdateProcessingChain("lux-update-chain"); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = UpdateDocCommand.makeSolrRequest(core); UpdateRequestProcessor processor = updateChain.createProcessor(req, rsp); processor.processDelete(cmd); processor.finish(); }
protected void doCommit () { boolean isCloud = shards != null && shards.length > 1; SolrQueryRequest req = new SolrQueryRequestBase (core, new ModifiableSolrParams()) {}; CommitUpdateCommand cmd = new CommitUpdateCommand(req, false); cmd.softCommit = true; // cmd.expungeDeletes = false; // cmd.waitFlush = true; // cmd.waitSearcher = true; LoggerFactory.getLogger(getClass()).debug ("commit {}", shards); try { if (isCloud) { SolrQueryResponse rsp = new SolrQueryResponse(); // ((ModifiableSolrParams)req.getParams()).add(ShardParams.SHARDS, getShardURLs(false)); UpdateRequestProcessorChain updateChain = core.getUpdateProcessingChain("lux-update-chain"); updateChain.createProcessor(req, rsp).processCommit(cmd); } else { // commit locally core.getUpdateHandler().commit(cmd); } } catch (IOException e) { throw new LuxException(e); } }
try { SolrCore core = req.getCore(); SolrQueryResponse rsp = new SolrQueryResponse(); SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp)); core.execute(core.getRequestHandler(handler),req,rsp);
public SolrQueryResponse handleSuggestionResponseRequest(ReSearcherRequestContext ctx, String query, String componentName, ResponseBuilder originalRb) throws Exception { ModifiableSolrParams newParams = new ModifiableSolrParams(originalRb.req.getParams()); newParams.set(CommonParams.Q, query); newParams.set(componentName, "false"); SolrQueryRequest req = new SolrQueryRequestBase(ctx.getCore(), newParams) {}; SolrQueryResponse rsp = new SolrQueryResponse(); ResponseBuilder rb = new ResponseBuilder(req, rsp, originalRb.components); try { handleSuggestionRequest(ctx, rb, originalRb.components, false); } finally { req.close(); } return rsp; }
private void getMoreTerms() { SolrRequestHandler termsHandler = xqueryComponent.getCore().getRequestHandler("/terms"); if (termsHandler == null) { LoggerFactory.getLogger(getClass()).error("No /terms handler configured; lux:field-terms giving up"); return; } ModifiableSolrParams params = new ModifiableSolrParams(); params.add(TermsParams.TERMS_FIELD, term.field()); if (current != null) { params.add(TermsParams.TERMS_LOWER, current); params.add(TermsParams.TERMS_LOWER_INCLUSIVE, "false"); offset = pos; } else { pos = 0; params.add(TermsParams.TERMS_LOWER, term.text()); } params.add(TermsParams.TERMS_SORT, TermsParams.TERMS_SORT_INDEX); params.add(TermsParams.TERMS_LIMIT, Integer.toString(100)); params.add("distrib", "true"); xqueryComponent.getCurrentShards(); params.add(ShardParams.SHARDS, StringUtils.join(xqueryComponent.getCurrentShards(), ",")); params.add(ShardParams.SHARDS_QT, "/terms"); // this gets passed to the shards to tell them what the request is SolrQueryRequest req = new CloudQueryRequest(xqueryComponent.getCore(), params, null); response = new SolrQueryResponse(); termsHandler.handleRequest(req, response); }
protected void processCommit(final String chain) throws IOException { SolrCore core = h.getCore(); UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain); assertNotNull("No Chain named: " + chain, pc); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams()); CommitUpdateCommand cmd = new CommitUpdateCommand(req,false); UpdateRequestProcessor processor = pc.createProcessor(req, rsp); try { processor.processCommit(cmd); } finally { req.close(); } }
protected void finish(final String chain) throws IOException { SolrCore core = h.getCore(); UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain); assertNotNull("No Chain named: " + chain, pc); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams()); UpdateRequestProcessor processor = pc.createProcessor(req, rsp); try { processor.finish(); } finally { IOUtils.closeQuietly(processor); req.close(); } }
protected void processDeleteById(final String chain, String id) throws IOException { SolrCore core = h.getCore(); UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain); assertNotNull("No Chain named: " + chain, pc); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams()); DeleteUpdateCommand cmd = new DeleteUpdateCommand(req); cmd.setId(id); UpdateRequestProcessor processor = pc.createProcessor(req, rsp); try { processor.processDelete(cmd); } finally { req.close(); } }
/** * @see org.opencms.search.CmsSearchIndex#createIndexBackup() */ @Override protected String createIndexBackup() { if (!isBackupReindexing()) { // if no backup is generated we don't need to do anything return null; } if (m_solr instanceof EmbeddedSolrServer) { EmbeddedSolrServer ser = (EmbeddedSolrServer)m_solr; CoreContainer con = ser.getCoreContainer(); SolrCore core = con.getCore(getCoreName()); if (core != null) { try { SolrRequestHandler h = core.getRequestHandler("/replication"); if (h instanceof ReplicationHandler) { h.handleRequest( new LocalSolrQueryRequest(core, CmsRequestUtil.createParameterMap("?command=backup")), new SolrQueryResponse()); } } finally { core.close(); } } } return null; }
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp){ SolrQueryResponse rsp1 = new SolrQueryResponse(), rsp2=new SolrQueryResponse(), rsp3=new SolrQueryResponse(); NamedList list = rsp.getValues(); rsp1.setAllValues(rsp.getValues().clone());
SolrQueryResponse response = new SolrQueryResponse();
public long handleSuggestionHitsRequest(ReSearcherRequestContext ctx, String query, Set<String> componentNames) throws Exception { ModifiableSolrParams params = new ModifiableSolrParams(ctx.getParams()); params.set(CommonParams.ROWS, "0"); for(String componentName : componentNames) { params.set(componentName, "false"); } params.set(CommonParams.Q, query); SolrQueryRequest req = new SolrQueryRequestBase(ctx.getCore(), params) {}; SolrQueryResponse rsp = new SolrQueryResponse(); ResponseBuilder rb = new ResponseBuilder(req, rsp, ctx.getQueryOnlyComponents()); try { handleSuggestionRequest(ctx, rb, ctx.getQueryOnlyComponents(), true); } finally { req.close(); } return ReSearcherUtils.extractOriginalQueryHits(rb); }
/** * Runs a document through the specified chain, and returns the final * document used when the chain is completed (NOTE: some chains may * modify the document in place */ protected SolrInputDocument processAdd(final String chain, final SolrParams requestParams, final SolrInputDocument docIn) throws IOException { SolrCore core = h.getCore(); UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain); assertNotNull("No Chain named: " + chain, pc); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = new LocalSolrQueryRequest(core, requestParams); try { SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp)); AddUpdateCommand cmd = new AddUpdateCommand(req); cmd.solrDoc = docIn; UpdateRequestProcessor processor = pc.createProcessor(req, rsp); if (null != processor) { // test chain might be empty or short circuited. processor.processAdd(cmd); } return cmd.solrDoc; } finally { SolrRequestInfo.clearRequestInfo(); req.close(); } }
private void doCloudSearch () { ResponseBuilder origRB = ((SolrQueryContext)eval.getQueryContext()).getResponseBuilder(); ModifiableSolrParams params = new ModifiableSolrParams(); params.add((CommonParams.Q), query); if (QueryParser.XML == queryParser) { params.add("defType", "xml"); } params.add(CommonParams.START, Integer.toString(position)); params.add(CommonParams.ROWS, Integer.toString(limit)); //params.add(CommonParams.FL, uriFieldName, xmlFieldName, idFieldName); params.add(CommonParams.FL, "*"); SolrParams origParams = origRB.req.getParams(); String debug = origParams.get(CommonParams.DEBUG); if (debug != null) { params.add(CommonParams.DEBUG, debug); } params.add("distrib", "true"); params.add("shards", origParams.get("shards")); SortSpec sortSpec = makeSortSpec(); addSortParam (params, sortSpec); XQueryComponent xqueryComponent = ((SolrQueryContext)eval.getQueryContext()).getQueryComponent(); SolrQueryRequest req = new CloudQueryRequest(xqueryComponent.getCore(), params, sortSpec); response = new SolrQueryResponse(); xqueryComponent.getSearchHandler().handleRequest(req, response); eval.getQueryStats().docCount += getResultNumFound(response); }
SolrQueryRequest solrReq = new SolrRestletQueryRequest(request, core); SolrQueryResponse solrResp = new SolrQueryResponse(); core.execute(handler, solrReq, solrResp);
/** * Runs a document through the specified chain, and returns the final * document used when the chain is completed (NOTE: some chains may * modify the document in place */ protected SolrInputDocument processAdd(final String chain, final SolrParams requestParams, final SolrInputDocument docIn) throws IOException { SolrCore core = h.getCore(); UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain); assertNotNull("No Chain named: " + chain, pc); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = new LocalSolrQueryRequest(core, requestParams); try { AddUpdateCommand cmd = new AddUpdateCommand(req); cmd.solrDoc = docIn; UpdateRequestProcessor processor = pc.createProcessor(req, rsp); processor.processAdd(cmd); return cmd.solrDoc; } finally { req.close(); } }