org.apache.solr.search.DocSlice Java Examples

The following examples show how to use org.apache.solr.search.DocSlice. 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: TaggerRequestHandler.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private DocList getDocList(int rows, FixedBitSet matchDocIdsBS) throws IOException {
  //Now we must supply a Solr DocList and add it to the response.
  //  Typically this is gotten via a SolrIndexSearcher.search(), but in this case we
  //  know exactly what documents to return, the order doesn't matter nor does
  //  scoring.
  //  Ideally an implementation of DocList could be directly implemented off
  //  of a BitSet, but there are way too many methods to implement for a minor
  //  payoff.
  int matchDocs = matchDocIdsBS.cardinality();
  int[] docIds = new int[ Math.min(rows, matchDocs) ];
  DocIdSetIterator docIdIter = new BitSetIterator(matchDocIdsBS, 1);
  for (int i = 0; i < docIds.length; i++) {
    docIds[i] = docIdIter.nextDoc();
  }
  return new DocSlice(0, docIds.length, docIds, null, matchDocs, 1f, TotalHits.Relation.EQUAL_TO);
}
 
Example #2
Source File: TaggerRequestHandler.java    From SolrTextTagger with Apache License 2.0 6 votes vote down vote up
private DocList getDocList(int rows, FixedBitSet matchDocIdsBS) throws IOException {
  //Now we must supply a Solr DocList and add it to the response.
  //  Typically this is gotten via a SolrIndexSearcher.search(), but in this case we
  //  know exactly what documents to return, the order doesn't matter nor does
  //  scoring.
  //  Ideally an implementation of DocList could be directly implemented off
  //  of a BitSet, but there are way too many methods to implement for a minor
  //  payoff.
  int matchDocs = matchDocIdsBS.cardinality();
  int[] docIds = new int[ Math.min(rows, matchDocs) ];
  DocIdSetIterator docIdIter = new BitSetIterator(matchDocIdsBS, 1);
  for (int i = 0; i < docIds.length; i++) {
    docIds[i] = docIdIter.nextDoc();
  }
  return new DocSlice(0, docIds.length, docIds, null, matchDocs, 1f);
}
 
Example #3
Source File: PageTool.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public PageTool(SolrQueryRequest request, SolrQueryResponse response) {
  String rows = request.getParams().get("rows");

  if (rows != null) {
    results_per_page = Integer.parseInt(rows);
  }
  //TODO: Handle group by results
  Object docs = response.getResponse();
  if (docs != null) {
    if (docs instanceof DocSlice) {
      results_found = ((DocSlice) docs).matches();
      start = ((DocSlice) docs).offset();
    } else if(docs instanceof ResultContext) {
      DocList dl = ((ResultContext) docs).getDocList();
      results_found = dl.matches();
      start = dl.offset();
    } else if(docs instanceof SolrDocumentList) {
      SolrDocumentList doc_list = (SolrDocumentList) docs;
      results_found = doc_list.getNumFound();
      start = doc_list.getStart();
    } else {
      throw new SolrException(SolrException.ErrorCode.UNKNOWN, "Unknown response type "+docs+". Expected one of DocSlice, ResultContext or SolrDocumentList");
    }
  }

  page_count = (int) Math.ceil(results_found / (double) results_per_page);
  current_page_number = (int) Math.ceil(start / (double) results_per_page) + (page_count > 0 ? 1 : 0);
}
 
Example #4
Source File: SubQueryAugmenterFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public DocList getDocList() {
  return new DocSlice((int)docList.getStart(), 
      docList.size(), new int[0], new float[docList.size()],
      (int) docList.getNumFound(), 
      docList.getMaxScore() == null ?  Float.NaN : docList.getMaxScore(),
          docList.getNumFoundExact() ? TotalHits.Relation.EQUAL_TO : TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO);
}
 
Example #5
Source File: ExpandComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
private void addGroupSliceToOutputMap(FieldType fieldType, IntObjectHashMap<BytesRef> ordBytes,
                                      @SuppressWarnings({"rawtypes"})NamedList outMap, CharsRefBuilder charsRef, long groupValue, DocSlice slice) {
  if(fieldType instanceof StrField) {
    final BytesRef bytesRef = ordBytes.get((int)groupValue);
    fieldType.indexedToReadable(bytesRef, charsRef);
    String group = charsRef.toString();
    outMap.add(group, slice);
  } else {
    outMap.add(numericToString(fieldType, groupValue), slice);
  }
}