Java Code Examples for org.apache.solr.common.SolrDocumentList#addAll()

The following examples show how to use org.apache.solr.common.SolrDocumentList#addAll() . 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: JavaBinCodec.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public SolrDocumentList readSolrDocumentList(DataInputInputStream dis) throws IOException {
  SolrDocumentList solrDocs = new SolrDocumentList();
  @SuppressWarnings("unchecked")
  List<Object> list = (List<Object>) readVal(dis);
  solrDocs.setNumFound((Long) list.get(0));
  solrDocs.setStart((Long) list.get(1));
  solrDocs.setMaxScore((Float) list.get(2));
  if (list.size() > 3) { //needed for back compatibility
    solrDocs.setNumFoundExact((Boolean)list.get(3));
  }

  @SuppressWarnings("unchecked")
  List<SolrDocument> l = (List<SolrDocument>) readVal(dis);
  solrDocs.addAll(l);
  return solrDocs;
}
 
Example 2
Source File: FastJavaBinDecoder.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public Object readObject(StreamCodec codec, EntryImpl entry) throws IOException {
  SolrDocumentList solrDocs = new SolrDocumentList();
  if(entry.metadata != null){
    @SuppressWarnings({"rawtypes"})
    List list = (List) entry.metadata;
    solrDocs.setNumFound((Long) list.get(0));
    solrDocs.setStart((Long) list.get(1));
    solrDocs.setMaxScore((Float) list.get(2));
    if (list.size() > 3) { //needed for back compatibility
      solrDocs.setNumFoundExact((Boolean)list.get(3));
    }
  }
  List<SolrDocument> l =  codec.readArray(codec.dis, entry.size);
  solrDocs.addAll(l);
  return solrDocs;
}
 
Example 3
Source File: RealTimeGetComponent.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void mergeResponses(ResponseBuilder rb) {
  SolrDocumentList docList = new SolrDocumentList();
  
  for (ShardRequest sreq : rb.finished) {
    // if shards=shard1,shard2 was used, then  we query both shards for each id and
    // can get more than one response
    for (ShardResponse srsp : sreq.responses) {
      SolrResponse sr = srsp.getSolrResponse();
      @SuppressWarnings({"rawtypes"})
      NamedList nl = sr.getResponse();
      SolrDocumentList subList = (SolrDocumentList)nl.get("response");
      docList.addAll(subList);
    }
  }
  
  addDocListToResponse(rb, docList);
}
 
Example 4
Source File: AutoCompleteSearchComponent.java    From solr-autocomplete with Apache License 2.0 5 votes vote down vote up
private void mergeDistributedResultsIntSingleResponse(ResponseBuilder rb, List<AcGroupResult> resultsToMerge, String responseTagName) {
  int docs = 0;
  float maxScore = 0.0f;
  
  // if groups have to be displayed in some custom order, other than the order specified in 
  // ac_grouping_field_def
  String groupingSort = rb.req.getParams().get(AC_GROUPING_SORT_PARAM_NAME);
  if (groupSorts.containsKey(groupingSort)) {
    groupSorts.get(groupingSort).sort(rb, resultsToMerge);
  }
  
  SolrDocumentList docList = new SolrDocumentList();
  // first find count of documents
  for (AcGroupResult acGroupResult : resultsToMerge) {
    // if slice contains more results than requested, take requested count; if it contains less results than
    // requested, we have to take what we got, not more
    docs += ((acGroupResult.getDistributedResultingDocs().size() > acGroupResult.getAcGroupingFieldValue().getRequestedCountOfSuggestions() == true) ? 
        acGroupResult.getAcGroupingFieldValue().getRequestedCountOfSuggestions() : acGroupResult.getDistributedResultingDocs().size());
    
    if (acGroupResult.getDistributedResultingDocs().getMaxScore() > maxScore) {
      maxScore = acGroupResult.getDistributedResultingDocs().getMaxScore();
    }
    
    docList.addAll(acGroupResult.getDistributedResultingDocs());
  }
  
  docList.setStart(0);
  docList.setNumFound(docs);

  rb.rsp.add(responseTagName, docList);
}
 
Example 5
Source File: AnalysisHandler.java    From chronix.server with Apache License 2.0 4 votes vote down vote up
/**
 * Executes the user search request.
 *
 * @param req the solr query request
 * @param rsp the solr query response holding the result
 * @throws Exception if bad things happen
 */
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    LOGGER.debug("Handling analysis request {}", req);
    //First check if the request should return documents => rows > 0
    final String rowsParam = req.getParams().get(CommonParams.ROWS, null);
    int rows = -1;
    if (rowsParam != null) {
        rows = Integer.parseInt(rowsParam);
    }

    SolrDocumentList results = new SolrDocumentList();

    final CQL cql = new CQL(TYPES, FUNCTIONS);

    //get the chronix join parameter
    final String chronixJoin = req.getParams().get(ChronixQueryParams.CHRONIX_JOIN);
    final CQLJoinFunction key = cql.parseCJ(chronixJoin);

    //Do a query and collect them on the join function
    final Map<ChronixType, Map<String, List<SolrDocument>>> collectedDocs = collectDocuments(req, key);

    //If no rows should returned, we only return the num found
    if (rows == 0) {
        results.setNumFound(collectedDocs.keySet().size());
    } else {
        //Otherwise return the analyzed time series

        final String chronixFunctions = req.getParams().get(ChronixQueryParams.CHRONIX_FUNCTION);
        final CQLCFResult result = cql.parseCF(chronixFunctions);

        final List<SolrDocument> resultDocuments = analyze(req, result, collectedDocs);
        results.addAll(resultDocuments);
        //As we have to analyze all docs in the query at once,
        // the number of documents is also the number of documents found
        results.setNumFound(resultDocuments.size());
    }
    //Add the results to the response
    rsp.add("response", results);
}