Search in sources :

Example 6 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)

Example 7 with MatchingDocs

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

the class TaxonomyFacetSumFloatAssociations method sumValues.

private final void sumValues(List<MatchingDocs> matchingDocs) throws IOException {
    //System.out.println("count matchingDocs=" + matchingDocs + " facetsField=" + facetsFieldName);
    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 docs = hits.bits.iterator();
        int doc;
        while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
            // BytesRef getAssociation()?
            if (dv.docID() < doc) {
                dv.advance(doc);
            }
            if (dv.docID() == doc) {
                final BytesRef bytesRef = dv.binaryValue();
                byte[] bytes = bytesRef.bytes;
                int end = bytesRef.offset + bytesRef.length;
                int offset = bytesRef.offset;
                while (offset < end) {
                    int ord = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF);
                    offset += 4;
                    int value = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF);
                    offset += 4;
                    values[ord] += Float.intBitsToFloat(value);
                }
            }
        }
    }
}
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)

Example 8 with MatchingDocs

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

the class TaxonomyFacetSumIntAssociations method sumValues.

private final void sumValues(List<MatchingDocs> matchingDocs) throws IOException {
    //System.out.println("count matchingDocs=" + matchingDocs + " facetsField=" + facetsFieldName);
    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 docs = hits.bits.iterator();
        int doc;
        while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
            // BytesRef getAssociation()?
            if (dv.docID() < doc) {
                dv.advance(doc);
            }
            if (dv.docID() == doc) {
                final BytesRef bytesRef = dv.binaryValue();
                byte[] bytes = bytesRef.bytes;
                int end = bytesRef.offset + bytesRef.length;
                int offset = bytesRef.offset;
                while (offset < end) {
                    int ord = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF);
                    offset += 4;
                    int value = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF);
                    offset += 4;
                    values[ord] += value;
                }
            }
        }
    }
}
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)

Example 9 with MatchingDocs

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

the class TaxonomyFacetSumValueSource method sumValues.

private void sumValues(List<MatchingDocs> matchingDocs, boolean keepScores, DoubleValuesSource valueSource) throws IOException {
    IntsRef scratch = new IntsRef();
    for (MatchingDocs hits : matchingDocs) {
        OrdinalsReader.OrdinalsSegmentReader ords = ordinalsReader.getReader(hits.context);
        DoubleValues scores = keepScores ? scores(hits) : null;
        DoubleValues functionValues = valueSource.getValues(hits.context, scores);
        DocIdSetIterator docs = hits.bits.iterator();
        int doc;
        while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
            ords.get(doc, scratch);
            if (functionValues.advanceExact(doc)) {
                float value = (float) functionValues.doubleValue();
                for (int i = 0; i < scratch.length; i++) {
                    values[scratch.ints[i]] += value;
                }
            }
        }
    }
    rollup();
}
Also used : MatchingDocs(org.apache.lucene.facet.FacetsCollector.MatchingDocs) DoubleValues(org.apache.lucene.search.DoubleValues) IntsRef(org.apache.lucene.util.IntsRef) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator)

Example 10 with MatchingDocs

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

the class LongRangeFacetCounts method count.

private void count(LongValuesSource valueSource, List<MatchingDocs> matchingDocs) throws IOException {
    LongRange[] ranges = (LongRange[]) this.ranges;
    LongRangeCounter counter = new LongRangeCounter(ranges);
    int missingCount = 0;
    for (MatchingDocs hits : matchingDocs) {
        LongValues 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(fv.longValue());
            } else {
                missingCount++;
            }
            doc = docs.nextDoc();
        }
    }
    int x = counter.fillCounts(counts);
    missingCount += x;
    //System.out.println("totCount " + totCount + " missingCount " + counter.missingCount);
    totCount -= missingCount;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) MatchingDocs(org.apache.lucene.facet.FacetsCollector.MatchingDocs) LongValues(org.apache.lucene.search.LongValues) Scorer(org.apache.lucene.search.Scorer) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) IndexReaderContext(org.apache.lucene.index.IndexReaderContext) Weight(org.apache.lucene.search.Weight)

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