Java Code Examples for org.apache.solr.request.SolrQueryRequestBase#setContentStreams()
The following examples show how to use
org.apache.solr.request.SolrQueryRequestBase#setContentStreams() .
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: 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 2
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 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: 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 5
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 6
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 7
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 8
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; }