Search in sources :

Example 11 with ConstantScoreScorer

use of org.apache.lucene.search.ConstantScoreScorer in project elasticsearch by elastic.

the class ParentToChildrenAggregator method doPostCollection.

@Override
protected void doPostCollection() throws IOException {
    IndexReader indexReader = context().searcher().getIndexReader();
    for (LeafReaderContext ctx : indexReader.leaves()) {
        Scorer childDocsScorer = childFilter.scorer(ctx);
        if (childDocsScorer == null) {
            continue;
        }
        DocIdSetIterator childDocsIter = childDocsScorer.iterator();
        final LeafBucketCollector sub = collectableSubAggregators.getLeafCollector(ctx);
        final SortedDocValues globalOrdinals = valuesSource.globalOrdinalsValues(parentType, ctx);
        // Set the scorer, since we now replay only the child docIds
        sub.setScorer(new ConstantScoreScorer(null, 1f, childDocsIter));
        final Bits liveDocs = ctx.reader().getLiveDocs();
        for (int docId = childDocsIter.nextDoc(); docId != DocIdSetIterator.NO_MORE_DOCS; docId = childDocsIter.nextDoc()) {
            if (liveDocs != null && liveDocs.get(docId) == false) {
                continue;
            }
            long globalOrdinal = globalOrdinals.getOrd(docId);
            if (globalOrdinal != -1) {
                long bucketOrd = parentOrdToBuckets.get(globalOrdinal);
                if (bucketOrd != -1) {
                    collectBucket(sub, docId, bucketOrd);
                    if (multipleBucketsPerParentOrd) {
                        long[] otherBucketOrds = parentOrdToOtherBuckets.get(globalOrdinal);
                        if (otherBucketOrds != null) {
                            for (long otherBucketOrd : otherBucketOrds) {
                                collectBucket(sub, docId, otherBucketOrd);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : LeafBucketCollector(org.elasticsearch.search.aggregations.LeafBucketCollector) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) IndexReader(org.apache.lucene.index.IndexReader) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) Scorer(org.apache.lucene.search.Scorer) Bits(org.apache.lucene.util.Bits) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) SortedDocValues(org.apache.lucene.index.SortedDocValues)

Example 12 with ConstantScoreScorer

use of org.apache.lucene.search.ConstantScoreScorer in project neo4j by neo4j.

the class DocValuesCollector method replayTo.

private void replayTo(Collector collector) throws IOException {
    for (MatchingDocs docs : getMatchingDocs()) {
        LeafCollector leafCollector = collector.getLeafCollector(docs.context);
        Scorer scorer;
        DocIdSetIterator idIterator = docs.docIdSet.iterator();
        if (isKeepScores()) {
            scorer = new ReplayingScorer(docs.scores);
        } else {
            scorer = new ConstantScoreScorer(null, Float.NaN, idIterator);
        }
        leafCollector.setScorer(scorer);
        int doc;
        while ((doc = idIterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
            leafCollector.collect(doc);
        }
    }
}
Also used : LeafCollector(org.apache.lucene.search.LeafCollector) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) Scorer(org.apache.lucene.search.Scorer) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator)

Example 13 with ConstantScoreScorer

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

the class Filter method createWeight.

//
// Query compatibility
//
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
    return new Weight(this) {

        @Override
        public void extractTerms(Set<Term> terms) {
        }

        @Override
        public Explanation explain(LeafReaderContext context, int doc) throws IOException {
            final Scorer scorer = scorer(context);
            final boolean match = (scorer != null && scorer.iterator().advance(doc) == doc);
            if (match) {
                assert scorer.score() == 0f;
                return Explanation.match(0f, "Match on id " + doc);
            } else {
                return Explanation.match(0f, "No match on id " + doc);
            }
        }

        @Override
        public Scorer scorer(LeafReaderContext context) throws IOException {
            final DocIdSet set = getDocIdSet(context, null);
            if (set == null) {
                return null;
            }
            if (applyLazily && set.bits() != null) {
                final Bits bits = set.bits();
                final DocIdSetIterator approximation = DocIdSetIterator.all(context.reader().maxDoc());
                final TwoPhaseIterator twoPhase = new TwoPhaseIterator(approximation) {

                    @Override
                    public boolean matches() throws IOException {
                        return bits.get(approximation.docID());
                    }

                    @Override
                    public float matchCost() {
                        // TODO use cost of bits.get()
                        return 10;
                    }
                };
                return new ConstantScoreScorer(this, 0f, twoPhase);
            }
            final DocIdSetIterator iterator = set.iterator();
            if (iterator == null) {
                return null;
            }
            return new ConstantScoreScorer(this, 0f, iterator);
        }
    };
}
Also used : Set(java.util.Set) DocIdSet(org.apache.lucene.search.DocIdSet) TwoPhaseIterator(org.apache.lucene.search.TwoPhaseIterator) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) Scorer(org.apache.lucene.search.Scorer) DocIdSet(org.apache.lucene.search.DocIdSet) Bits(org.apache.lucene.util.Bits) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) Weight(org.apache.lucene.search.Weight)

Example 14 with ConstantScoreScorer

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

the class CompositeVerifyQuery method createWeight.

@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
    //scores aren't unsupported
    final Weight indexQueryWeight = indexQuery.createWeight(searcher, false, boost);
    final Map valueSourceContext = ValueSource.newContext(searcher);
    return new ConstantScoreWeight(this, boost) {

        @Override
        public Scorer scorer(LeafReaderContext context) throws IOException {
            final Scorer indexQueryScorer = indexQueryWeight.scorer(context);
            if (indexQueryScorer == null) {
                return null;
            }
            final FunctionValues predFuncValues = predicateValueSource.getValues(valueSourceContext, context);
            final TwoPhaseIterator twoPhaseIterator = new TwoPhaseIterator(indexQueryScorer.iterator()) {

                @Override
                public boolean matches() throws IOException {
                    return predFuncValues.boolVal(indexQueryScorer.docID());
                }

                @Override
                public float matchCost() {
                    // TODO: use cost of predFuncValues.boolVal()
                    return 100;
                }
            };
            return new ConstantScoreScorer(this, score(), twoPhaseIterator);
        }
    };
}
Also used : TwoPhaseIterator(org.apache.lucene.search.TwoPhaseIterator) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) Scorer(org.apache.lucene.search.Scorer) FunctionValues(org.apache.lucene.queries.function.FunctionValues) Map(java.util.Map) Weight(org.apache.lucene.search.Weight) ConstantScoreWeight(org.apache.lucene.search.ConstantScoreWeight) ConstantScoreWeight(org.apache.lucene.search.ConstantScoreWeight)

Example 15 with ConstantScoreScorer

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

the class AbstractPrefixTreeQuery method createWeight.

@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
    return new ConstantScoreWeight(this, boost) {

        @Override
        public Scorer scorer(LeafReaderContext context) throws IOException {
            DocIdSet docSet = getDocIdSet(context);
            if (docSet == null) {
                return null;
            }
            DocIdSetIterator disi = docSet.iterator();
            if (disi == null) {
                return null;
            }
            return new ConstantScoreScorer(this, score(), disi);
        }
    };
}
Also used : ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) DocIdSet(org.apache.lucene.search.DocIdSet) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) ConstantScoreWeight(org.apache.lucene.search.ConstantScoreWeight)

Aggregations

ConstantScoreScorer (org.apache.lucene.search.ConstantScoreScorer)19 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)18 ConstantScoreWeight (org.apache.lucene.search.ConstantScoreWeight)15 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)10 TwoPhaseIterator (org.apache.lucene.search.TwoPhaseIterator)9 Scorer (org.apache.lucene.search.Scorer)6 Weight (org.apache.lucene.search.Weight)5 IOException (java.io.IOException)4 LeafReader (org.apache.lucene.index.LeafReader)4 PointValues (org.apache.lucene.index.PointValues)4 DocIdSetBuilder (org.apache.lucene.util.DocIdSetBuilder)4 FieldInfo (org.apache.lucene.index.FieldInfo)3 IntersectVisitor (org.apache.lucene.index.PointValues.IntersectVisitor)3 SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)3 DocIdSet (org.apache.lucene.search.DocIdSet)3 Map (java.util.Map)2 Set (java.util.Set)2 Rectangle (org.apache.lucene.geo.Rectangle)2 IndexReader (org.apache.lucene.index.IndexReader)2 Relation (org.apache.lucene.index.PointValues.Relation)2