org.apache.solr.request.SolrQueryRequestBase Java Examples
The following examples show how to use
org.apache.solr.request.SolrQueryRequestBase.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRerankBase.java From lucene-solr with Apache License 2.0 | 6 votes |
protected static void bulkIndex(String filePath) throws Exception { final SolrQueryRequestBase req = lrf.makeRequest( CommonParams.STREAM_CONTENTTYPE, "application/xml"); final List<ContentStream> streams = new ArrayList<ContentStream>(); final File file = new File(filePath); streams.add(new ContentStreamBase.FileStream(file)); req.setContentStreams(streams); try { final SolrQueryResponse res = new SolrQueryResponse(); h.updater.handleRequest(req, res); } catch (final Throwable ex) { // Ignore. Just log the exception and go to the next file log.error(ex.getMessage(), ex); } assertU(commit()); }
Example #2
Source File: SolrTestCaseJ4.java From lucene-solr with Apache License 2.0 | 6 votes |
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(); }
Example #3
Source File: UniqFieldsUpdateProcessorFactoryTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private void addDoc(String doc) throws Exception { Map<String, String[]> params = new HashMap<>(); MultiMapSolrParams mmparams = new MultiMapSolrParams(params); params.put(UpdateParams.UPDATE_CHAIN, new String[] { "uniq-fields" }); 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(); }
Example #4
Source File: ReSearcherHandler.java From solr-researcher with Apache License 2.0 | 6 votes |
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); }
Example #5
Source File: AbstractTaggerTest.java From SolrTextTagger with Apache License 2.0 | 5 votes |
/** REMEMBER to close() the result req object. */ protected SolrQueryRequest reqDoc(String doc, SolrParams moreParams) { log.debug("Test doc: "+doc); SolrParams params = SolrParams.wrapDefaults(moreParams, baseParams); SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), params) {}; Iterable<ContentStream> stream = Collections.singleton((ContentStream)new ContentStreamBase.StringStream(doc)); req.setContentStreams(stream); return req; }
Example #6
Source File: UpdateIndexAuthorizationProcessorTest.java From incubator-sentry with Apache License 2.0 | 5 votes |
private void verifyAuthorized(String collection, String user) throws Exception { SolrQueryRequestBase req = new SolrQueryRequestBase(core, new MapSolrParams(new HashMap())) {}; getProcessor(collection, user).processAdd(new AddUpdateCommand(req)); getProcessor(collection, user).processDelete(new DeleteUpdateCommand(req)); DeleteUpdateCommand deleteByQueryCommand = new DeleteUpdateCommand(req); deleteByQueryCommand.setQuery("*:*"); getProcessor(collection, user).processDelete(deleteByQueryCommand); getProcessor(collection, user).processMergeIndexes(new MergeIndexesCommand(null, req)); getProcessor(collection, user).processCommit(new CommitUpdateCommand(req, false)); getProcessor(collection, user).processRollback(new RollbackUpdateCommand(req)); getProcessor(collection, user).finish(); }
Example #7
Source File: BaseTestCase.java From BioSolr with Apache License 2.0 | 5 votes |
public static SolrQueryResponse query(SolrCore core, String handlerName, SolrParams params) { SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = new SolrQueryRequestBase(core, params) { }; try { SolrRequestHandler handler = core.getRequestHandler(handlerName); core.execute(handler, req, rsp); return rsp; } finally { req.close(); } }
Example #8
Source File: OntologyUpdateProcessorFactoryTest.java From BioSolr with Apache License 2.0 | 5 votes |
static void addDoc(String doc, String chain) throws Exception { Map<String, String[]> params = new HashMap<>(); MultiMapSolrParams mmparams = new MultiMapSolrParams(params); params.put(UpdateParams.UPDATE_CHAIN, new String[] { chain }); SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), 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(); }
Example #9
Source File: ReSearcherHandler.java From solr-researcher with Apache License 2.0 | 5 votes |
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; }
Example #10
Source File: DocumentAnalysisRequestHandlerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testCharsetOutsideDocument() throws Exception { final byte[] xmlBytes = ( "<docs>\r\n" + " <doc>\r\n" + " <field name=\"id\">Müller</field>\r\n" + " </doc>" + "</docs>" ).getBytes(StandardCharsets.ISO_8859_1); // we declare a content stream with charset: final ContentStream cs = new ByteStream(xmlBytes, "application/xml; charset=ISO-8859-1"); ModifiableSolrParams params = new ModifiableSolrParams(); SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) { @Override public Iterable<ContentStream> getContentStreams() { return Collections.singleton(cs); } }; DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req); assertNotNull(request); final List<SolrInputDocument> documents = request.getDocuments(); assertNotNull(documents); assertEquals(1, documents.size()); SolrInputDocument doc = documents.get(0); assertEquals("Müller", doc.getField("id").getValue()); }
Example #11
Source File: DocumentAnalysisRequestHandlerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testCharsetInDocument() throws Exception { final byte[] xmlBytes = ( "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n" + "<docs>\r\n" + " <doc>\r\n" + " <field name=\"id\">Müller</field>\r\n" + " </doc>" + "</docs>" ).getBytes(StandardCharsets.ISO_8859_1); // we declare a content stream without charset: final ContentStream cs = new ByteStream(xmlBytes, "application/xml"); ModifiableSolrParams params = new ModifiableSolrParams(); SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) { @Override public Iterable<ContentStream> getContentStreams() { return Collections.singleton(cs); } }; DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req); assertNotNull(request); final List<SolrInputDocument> documents = request.getDocuments(); assertNotNull(documents); assertEquals(1, documents.size()); SolrInputDocument doc = documents.get(0); assertEquals("Müller", doc.getField("id").getValue()); }
Example #12
Source File: MoreLikeThisHandlerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testMultifieldSimilarity() throws Exception { SolrCore core = h.getCore(); ModifiableSolrParams params = new ModifiableSolrParams(); assertU(adoc("id", "1", "name", "aaa bbb ccc", "subword", " zzz")); assertU(adoc("id", "2", "name", " bbb ccc", "subword", " bbb zzz")); assertU(adoc("id", "3", "name", " ccc", "subword", "aaa bbb zzz")); assertU(adoc("id", "4", "name", " ccc", "subword", " bbb ")); assertU(commit()); params.set(CommonParams.QT, "/mlt"); params.set(MoreLikeThisParams.MLT, "true"); params.set(MoreLikeThisParams.SIMILARITY_FIELDS, "name,subword"); params.set(MoreLikeThisParams.INTERESTING_TERMS, "details"); params.set(MoreLikeThisParams.MIN_TERM_FREQ, "1"); params.set(MoreLikeThisParams.MIN_DOC_FREQ, "2"); params.set(MoreLikeThisParams.BOOST, true); params.set("indent", "true"); try (SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {}) { ArrayList<ContentStream> streams = new ArrayList<>(2); streams.add(new ContentStreamBase.StringStream("bbb", "zzz")); req.setContentStreams(streams); // Make sure we have terms from both fields in the interestingTerms array and all documents have been // retrieved as matching. assertQ(req, "//lst[@name = 'interestingTerms']/float[@name = 'subword:bbb']", "//lst[@name = 'interestingTerms']/float[@name = 'name:bbb']", "//result[@name = 'response' and @numFound = '4']"); } }
Example #13
Source File: TaggerTestCase.java From lucene-solr with Apache License 2.0 | 5 votes |
/** REMEMBER to close() the result req object. */ protected SolrQueryRequest reqDoc(String doc, SolrParams moreParams) { log.debug("Test doc: {}", doc); SolrParams params = SolrParams.wrapDefaults(moreParams, baseParams); SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), params) {}; Iterable<ContentStream> stream = Collections.singleton((ContentStream)new ContentStreamBase.StringStream(doc)); req.setContentStreams(stream); return req; }
Example #14
Source File: MaxSizeAutoCommitTest.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Helper for constructing a batch update request * @param startId the document ID to begin with * @param batchSize the number of documents to include in the batch * @param requestFn a function that takes an (int) ID and returns an XML string of the request to add to the batch request * @return a SolrQueryRequestBase */ private SolrQueryRequestBase constructBatchRequestHelper(int startId, int batchSize, Function<Integer, String> requestFn) { SolrQueryRequestBase updateReq = new SolrQueryRequestBase(core, new MapSolrParams(new HashMap<>())) {}; List<String> docs = new ArrayList<>(); for (int i = startId; i < startId + batchSize; i++) { docs.add(requestFn.apply(i)); } updateReq.setContentStreams(toContentStreams(docs)); return updateReq; }
Example #15
Source File: MaxSizeAutoCommitTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testRedundantDeletes() throws Exception { Assert.assertEquals("There have been no updates yet, so there shouldn't have been any commits", 0, hardCommitTracker.getCommitCount()); long tlogSizePreUpdates = updateHandler.getUpdateLog().getCurrentLogSizeFromStream(); Assert.assertEquals("There have been no updates yet, so tlog should be empty", 0, tlogSizePreUpdates); // Add docs int numDocsToAdd = 150; SolrQueryResponse updateResp = new SolrQueryResponse(); monitor.doStuffAndExpectAtLeastOneCommit(hardCommitTracker, updateHandler, () -> { updateRequestHandler.handleRequest(constructBatchAddDocRequest(0, numDocsToAdd), updateResp); }); // Send a bunch of redundant deletes int numDeletesToSend = 500; int docIdToDelete = 100; SolrQueryRequestBase batchSingleDeleteRequest = new SolrQueryRequestBase(core, new MapSolrParams(new HashMap<>())) {}; List<String> docs = new ArrayList<>(); for (int i = 0; i < numDeletesToSend; i++) { docs.add(delI(Integer.toString(docIdToDelete))); } batchSingleDeleteRequest.setContentStreams(toContentStreams(docs)); monitor.doStuffAndExpectAtLeastOneCommit(hardCommitTracker, updateHandler, () -> { updateRequestHandler.handleRequest(batchSingleDeleteRequest, updateResp); }); }
Example #16
Source File: CloudMLTQParser.java From lucene-solr with Apache License 2.0 | 5 votes |
private SolrDocument getDocument(String id) { SolrCore core = req.getCore(); SolrQueryResponse rsp = new SolrQueryResponse(); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(ID, id); SolrQueryRequestBase request = new SolrQueryRequestBase(core, params) { }; core.getRequestHandler("/get").handleRequest(request, rsp); @SuppressWarnings({"rawtypes"}) NamedList response = rsp.getValues(); return (SolrDocument) response.get("doc"); }
Example #17
Source File: DocumentAnalysisRequestHandlerTest.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * Tests the {@link DocumentAnalysisRequestHandler#resolveAnalysisRequest(org.apache.solr.request.SolrQueryRequest)} */ @Test public void testResolveAnalysisRequest() throws Exception { String docsInput = "<docs>" + "<doc>" + "<field name=\"id\">1</field>" + "<field name=\"whitetok\">The Whitetok</field>" + "<field name=\"text\">The Text</field>" + "</doc>" + "</docs>"; final ContentStream cs = new ContentStreamBase.StringStream(docsInput); ModifiableSolrParams params = new ModifiableSolrParams(); params.add("analysis.query", "The Query String"); params.add("analysis.showmatch", "true"); SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) { @Override public Iterable<ContentStream> getContentStreams() { return Collections.singleton(cs); } }; DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req); assertNotNull(request); assertTrue(request.isShowMatch()); assertNotNull(request.getQuery()); assertEquals("The Query String", request.getQuery()); List<SolrInputDocument> documents = request.getDocuments(); assertNotNull(documents); assertEquals(1, documents.size()); SolrInputDocument document = documents.get(0); SolrInputField field = document.getField("id"); assertNotNull(field); assertEquals("1", field.getFirstValue()); field = document.getField("whitetok"); assertNotNull(field); assertEquals("The Whitetok", field.getFirstValue()); field = document.getField("text"); assertNotNull(field); assertEquals("The Text", field.getFirstValue()); req.close(); }
Example #18
Source File: SentryTestBase.java From incubator-sentry with Apache License 2.0 | 4 votes |
public void setUp(SolrCore core) throws Exception { super.setUp(); request = new SolrQueryRequestBase( core, new ModifiableSolrParams() ) { }; }
Example #19
Source File: MaxSizeAutoCommitTest.java From lucene-solr with Apache License 2.0 | 2 votes |
/** * Construct a batch delete document request, with IDs incrementing from startId * @param startId the document ID to begin with * @param batchSize the number of documents to include in the batch * @return a SolrQueryRequestBase */ private SolrQueryRequestBase constructBatchDeleteDocRequest(int startId, int batchSize) { return constructBatchRequestHelper(startId, batchSize, DELETE_DOC_FN); }
Example #20
Source File: MaxSizeAutoCommitTest.java From lucene-solr with Apache License 2.0 | 2 votes |
/** * Construct a batch add document request with a series of very simple Solr docs with increasing IDs. * @param startId the document ID to begin with * @param batchSize the number of documents to include in the batch * @return a SolrQueryRequestBase */ private SolrQueryRequestBase constructBatchAddDocRequest(int startId, int batchSize) { return constructBatchRequestHelper(startId, batchSize, ADD_DOC_FN); }