Search in sources :

Example 1 with MatchingDocs

use of org.apache.lucene.facet.FacetsCollector.MatchingDocs in project lucene-solr by apache.

the class DoubleRangeFacetCounts method count.

private void count(DoubleValuesSource valueSource, List<MatchingDocs> matchingDocs) throws IOException {
    DoubleRange[] ranges = (DoubleRange[]) this.ranges;
    LongRange[] longRanges = new LongRange[ranges.length];
    for (int i = 0; i < ranges.length; i++) {
        DoubleRange range = ranges[i];
        longRanges[i] = new LongRange(range.label, NumericUtils.doubleToSortableLong(range.min), true, NumericUtils.doubleToSortableLong(range.max), true);
    }
    LongRangeCounter counter = new LongRangeCounter(longRanges);
    int missingCount = 0;
    for (MatchingDocs hits : matchingDocs) {
        DoubleValues fv = valueSource.getValues(hits.context, null);
        totCount += hits.totalHits;
        final DocIdSetIterator fastMatchDocs;
        if (fastMatchQuery != null) {
            final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(hits.context);
            final IndexSearcher searcher = new IndexSearcher(topLevelContext);
            searcher.setQueryCache(null);
            final Weight fastMatchWeight = searcher.createNormalizedWeight(fastMatchQuery, false);
            Scorer s = fastMatchWeight.scorer(hits.context);
            if (s == null) {
                continue;
            }
            fastMatchDocs = s.iterator();
        } else {
            fastMatchDocs = null;
        }
        DocIdSetIterator docs = hits.bits.iterator();
        for (int doc = docs.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; ) {
            if (fastMatchDocs != null) {
                int fastMatchDoc = fastMatchDocs.docID();
                if (fastMatchDoc < doc) {
                    fastMatchDoc = fastMatchDocs.advance(doc);
                }
                if (doc != fastMatchDoc) {
                    doc = docs.advance(fastMatchDoc);
                    continue;
                }
            }
            // Skip missing docs:
            if (fv.advanceExact(doc)) {
                counter.add(NumericUtils.doubleToSortableLong(fv.doubleValue()));
            } else {
                missingCount++;
            }
            doc = docs.nextDoc();
        }
    }
    missingCount += counter.fillCounts(counts);
    totCount -= missingCount;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) MatchingDocs(org.apache.lucene.facet.FacetsCollector.MatchingDocs) DoubleValues(org.apache.lucene.search.DoubleValues) Scorer(org.apache.lucene.search.Scorer) IndexReaderContext(org.apache.lucene.index.IndexReaderContext) Weight(org.apache.lucene.search.Weight) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator)

Example 2 with MatchingDocs

use of org.apache.lucene.facet.FacetsCollector.MatchingDocs in project lucene-solr by apache.

the class ConcurrentSortedSetDocValuesFacetCounts method count.

/** Does all the "real work" of tallying up the counts. */
private final void count(List<MatchingDocs> matchingDocs) throws IOException, InterruptedException {
    MultiDocValues.OrdinalMap ordinalMap;
    // matchingDocs...
    if (dv instanceof MultiDocValues.MultiSortedSetDocValues && matchingDocs.size() > 1) {
        ordinalMap = ((MultiSortedSetDocValues) dv).mapping;
    } else {
        ordinalMap = null;
    }
    IndexReader reader = state.getReader();
    List<Future<Void>> results = new ArrayList<>();
    for (MatchingDocs hits : matchingDocs) {
        // AIOOBE can happen:
        if (ReaderUtil.getTopLevelContext(hits.context).reader() != reader) {
            throw new IllegalStateException("the SortedSetDocValuesReaderState provided to this class does not match the reader being searched; you must create a new SortedSetDocValuesReaderState every time you open a new IndexReader");
        }
        results.add(exec.submit(new CountOneSegment(hits.context.reader(), hits, ordinalMap, hits.context.ord)));
    }
    for (Future<Void> result : results) {
        try {
            result.get();
        } catch (ExecutionException ee) {
            // Theoretically cause can be null; guard against that.
            Throwable cause = ee.getCause();
            throw IOUtils.rethrowAlways(cause != null ? cause : ee);
        }
    }
}
Also used : MatchingDocs(org.apache.lucene.facet.FacetsCollector.MatchingDocs) ArrayList(java.util.ArrayList) MultiDocValues(org.apache.lucene.index.MultiDocValues) IndexReader(org.apache.lucene.index.IndexReader) Future(java.util.concurrent.Future) MultiSortedSetDocValues(org.apache.lucene.index.MultiDocValues.MultiSortedSetDocValues) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with MatchingDocs

use of org.apache.lucene.facet.FacetsCollector.MatchingDocs in project lucene-solr by apache.

the class TaxonomyFacetCounts method count.

private final void count(List<MatchingDocs> matchingDocs) throws IOException {
    IntsRef scratch = new IntsRef();
    for (MatchingDocs hits : matchingDocs) {
        OrdinalsReader.OrdinalsSegmentReader ords = ordinalsReader.getReader(hits.context);
        DocIdSetIterator docs = hits.bits.iterator();
        int doc;
        while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
            ords.get(doc, scratch);
            for (int i = 0; i < scratch.length; i++) {
                values[scratch.ints[scratch.offset + i]]++;
            }
        }
    }
    rollup();
}
Also used : MatchingDocs(org.apache.lucene.facet.FacetsCollector.MatchingDocs) IntsRef(org.apache.lucene.util.IntsRef) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator)

Example 4 with MatchingDocs

use of org.apache.lucene.facet.FacetsCollector.MatchingDocs in project lucene-solr by apache.

the class SortedSetDocValuesFacetCounts method count.

/** Does all the "real work" of tallying up the counts. */
private final void count(List<MatchingDocs> matchingDocs) throws IOException {
    //System.out.println("ssdv count");
    MultiDocValues.OrdinalMap ordinalMap;
    // matchingDocs...
    if (dv instanceof MultiDocValues.MultiSortedSetDocValues && matchingDocs.size() > 1) {
        ordinalMap = ((MultiSortedSetDocValues) dv).mapping;
    } else {
        ordinalMap = null;
    }
    IndexReader reader = state.getReader();
    for (MatchingDocs hits : matchingDocs) {
        // AIOOBE can happen:
        if (ReaderUtil.getTopLevelContext(hits.context).reader() != reader) {
            throw new IllegalStateException("the SortedSetDocValuesReaderState provided to this class does not match the reader being searched; you must create a new SortedSetDocValuesReaderState every time you open a new IndexReader");
        }
        countOneSegment(ordinalMap, hits.context.reader(), hits.context.ord, hits);
    }
}
Also used : MatchingDocs(org.apache.lucene.facet.FacetsCollector.MatchingDocs) IndexReader(org.apache.lucene.index.IndexReader) MultiSortedSetDocValues(org.apache.lucene.index.MultiDocValues.MultiSortedSetDocValues) MultiDocValues(org.apache.lucene.index.MultiDocValues)

Example 5 with MatchingDocs

use of org.apache.lucene.facet.FacetsCollector.MatchingDocs in project lucene-solr by apache.

the class FastTaxonomyFacetCounts method count.

private final void count(List<MatchingDocs> matchingDocs) throws IOException {
    for (MatchingDocs hits : matchingDocs) {
        BinaryDocValues dv = hits.context.reader().getBinaryDocValues(indexFieldName);
        if (dv == null) {
            // this reader does not have DocValues for the requested category list
            continue;
        }
        DocIdSetIterator it = ConjunctionDISI.intersectIterators(Arrays.asList(hits.bits.iterator(), dv));
        for (int doc = it.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = it.nextDoc()) {
            final BytesRef bytesRef = dv.binaryValue();
            byte[] bytes = bytesRef.bytes;
            int end = bytesRef.offset + bytesRef.length;
            int ord = 0;
            int offset = bytesRef.offset;
            int prev = 0;
            while (offset < end) {
                byte b = bytes[offset++];
                if (b >= 0) {
                    prev = ord = ((ord << 7) | b) + prev;
                    ++values[ord];
                    ord = 0;
                } else {
                    ord = (ord << 7) | (b & 0x7F);
                }
            }
        }
    }
    rollup();
}
Also used : MatchingDocs(org.apache.lucene.facet.FacetsCollector.MatchingDocs) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) BinaryDocValues(org.apache.lucene.index.BinaryDocValues) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

MatchingDocs (org.apache.lucene.facet.FacetsCollector.MatchingDocs)10 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)8 BinaryDocValues (org.apache.lucene.index.BinaryDocValues)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 BytesRef (org.apache.lucene.util.BytesRef)3 IndexReader (org.apache.lucene.index.IndexReader)2 IndexReaderContext (org.apache.lucene.index.IndexReaderContext)2 MultiDocValues (org.apache.lucene.index.MultiDocValues)2 MultiSortedSetDocValues (org.apache.lucene.index.MultiDocValues.MultiSortedSetDocValues)2 DoubleValues (org.apache.lucene.search.DoubleValues)2 Scorer (org.apache.lucene.search.Scorer)2 Weight (org.apache.lucene.search.Weight)2 IntsRef (org.apache.lucene.util.IntsRef)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 Document (org.apache.lucene.document.Document)1 StringField (org.apache.lucene.document.StringField)1 FastTaxonomyFacetCounts (org.apache.lucene.facet.taxonomy.FastTaxonomyFacetCounts)1