List of usage examples for org.apache.solr.client.solrj StreamingResponseCallback streamSolrDocument
public abstract void streamSolrDocument(SolrDocument doc);
From source file:org.opensextant.extraction.SolrMatcherSupport.java
License:Apache License
/** * Solr call: tag input buffer, returning all candiate reference data that * matched during tagging./*from ww w . j a v a 2 s . c om*/ * * @param buffer text to tag * @param docid id for text, only for tracking purposes * @param refDataMap * - a map of reference data in solr, It will store caller's * domain objects. e.g., rec.id => domain(rec) * @return solr response * @throws ExtractionException tagger error */ protected QueryResponse tagTextCallSolrTagger(String buffer, String docid, final Map<Integer, Object> refDataMap) throws ExtractionException { SolrTaggerRequest tagRequest = new SolrTaggerRequest(getMatcherParameters(), buffer); tagRequest.setPath(requestHandler); // Stream the response to avoid serialization and to save memory by // only keeping one SolrDocument materialized at a time tagRequest.setStreamingResponseCallback(new StreamingResponseCallback() { @Override public void streamDocListInfo(long numFound, long start, Float maxScore) { } // Future optimization: it would be nice if Solr could give us the // doc id without giving us a SolrDocument, allowing us to // conditionally get it. It would save disk IO & speed, at the // expense of putting ids into memory. @Override public void streamSolrDocument(final SolrDocument solrDoc) { Integer id = (Integer) solrDoc.getFirstValue("id"); // create a domain object for the given tag; // this callback handler caches such domain obj in simple k/v // map. Object domainObj = createTag(solrDoc); if (domainObj != null) { refDataMap.put(id, domainObj); } } }); QueryResponse response; try { response = tagRequest.process(solr.getInternalSolrServer()); } catch (Exception err) { throw new ExtractionException("Failed to tag document=" + docid, err); } // see https://issues.apache.org/jira/browse/SOLR-5154 SolrDocumentList docList = response.getResults(); if (docList != null) { // log.debug("Not streaming docs from Solr (not supported)"); StreamingResponseCallback callback = tagRequest.getStreamingResponseCallback(); callback.streamDocListInfo(docList.getNumFound(), docList.getStart(), docList.getMaxScore()); for (SolrDocument solrDoc : docList) { /** * This appears to be an empty list; what is this explicit * callback loop for? */ callback.streamSolrDocument(solrDoc); } } return response; }