Search in sources :

Example 1 with LongValues

use of org.apache.lucene.search.LongValues 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)

Example 2 with LongValues

use of org.apache.lucene.search.LongValues in project lucene-solr by apache.

the class ValueSource method asLongValuesSource.

/**
   * Expose this ValueSource as a LongValuesSource
   */
public LongValuesSource asLongValuesSource() {
    return new LongValuesSource() {

        @Override
        public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
            Map context = new IdentityHashMap<>();
            FakeScorer scorer = new FakeScorer();
            context.put("scorer", scorer);
            final FunctionValues fv = ValueSource.this.getValues(context, ctx);
            return new LongValues() {

                @Override
                public long longValue() throws IOException {
                    return fv.longVal(scorer.current);
                }

                @Override
                public boolean advanceExact(int doc) throws IOException {
                    scorer.current = doc;
                    if (scores != null && scores.advanceExact(doc))
                        scorer.score = (float) scores.doubleValue();
                    else
                        scorer.score = 0;
                    return fv.exists(doc);
                }
            };
        }

        @Override
        public boolean needsScores() {
            return false;
        }
    };
}
Also used : IdentityHashMap(java.util.IdentityHashMap) DoubleValues(org.apache.lucene.search.DoubleValues) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) LongValues(org.apache.lucene.search.LongValues) LongValuesSource(org.apache.lucene.search.LongValuesSource) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

LongValues (org.apache.lucene.search.LongValues)2 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 MatchingDocs (org.apache.lucene.facet.FacetsCollector.MatchingDocs)1 IndexReaderContext (org.apache.lucene.index.IndexReaderContext)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)1 DoubleValues (org.apache.lucene.search.DoubleValues)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 LongValuesSource (org.apache.lucene.search.LongValuesSource)1 Scorer (org.apache.lucene.search.Scorer)1 Weight (org.apache.lucene.search.Weight)1