Java 类org.apache.lucene.search.ConstantScoreScorer 实例源码

项目:elasticsearch-learning-to-rank    文件:RankerQuery.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    if (!needsScores) {
        // If scores are not needed simply return a constant score on all docs
        return new ConstantScoreWeight(this) {
            @Override
            public Scorer scorer(LeafReaderContext context) throws IOException {
                return new ConstantScoreScorer(this, score(), DocIdSetIterator.all(context.reader().maxDoc()));
            }
        };
    }
    List<Weight> weights = new ArrayList<>(queries.size());
    for (Query q : queries) {
        weights.add(searcher.createWeight(q, needsScores));
    }
    return new RankerWeight(weights);
}
项目:neo4j-lucene5-index    文件:DocValuesCollector.java   
private boolean ensureValidDisi()
{
    while ( currentDisi == null && docs.hasNext() )
    {
        MatchingDocs matchingDocs = docs.next();
        try
        {
            currentDisi = matchingDocs.docIdSet.iterator();
            if ( keepScores )
            {
                currentScorer = new ReplayingScorer( matchingDocs.scores );
            }
            else
            {
                currentScorer = new ConstantScoreScorer( null, Float.NaN, currentDisi );
            }
            currentReader = matchingDocs.context.reader();
        }
        catch ( IOException e )
        {
            throw new RuntimeException( e );
        }
    }
    return currentDisi != null;
}
项目:elasticsearch_my    文件:ParentToChildrenAggregator.java   
@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);
                            }
                        }
                    }
                }
            }
        }
    }
}
项目:elasticsearch_my    文件:TermsSliceQuery.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    return new ConstantScoreWeight(this) {
        @Override
        public Scorer scorer(LeafReaderContext context) throws IOException {
            final DocIdSet disi = build(context.reader());
            final DocIdSetIterator leafIt = disi.iterator();
            return new ConstantScoreScorer(this, score(), leafIt);
        }
    };
}
项目:elasticsearch_my    文件:IndicesQueryCacheTests.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores)
        throws IOException {
    return new ConstantScoreWeight(this) {
        @Override
        public Scorer scorer(LeafReaderContext context) throws IOException {
            return new ConstantScoreScorer(this, score(), DocIdSetIterator.all(context.reader().maxDoc()));
        }
    };
}
项目:elasticsearch-learning-to-rank    文件:DerivedExpressionQuery.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    if (!needsScores) {
        // If scores are not needed simply return a constant score on all docs
        return new ConstantScoreWeight(this) {
            @Override
            public Scorer scorer(LeafReaderContext context) throws IOException {
                return new ConstantScoreScorer(this, score(), DocIdSetIterator.all(context.reader().maxDoc()));
            }
        };
    }

    return new FVWeight(this);
}
项目:elasticsearch_my    文件:InnerHitsContext.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    final Weight childWeight = childFilter.createWeight(searcher, false);
    return new ConstantScoreWeight(this) {
        @Override
        public Scorer scorer(LeafReaderContext context) throws IOException {
            // Nested docs only reside in a single segment, so no need to evaluate all segments
            if (!context.reader().getCoreCacheKey().equals(leafReader.getCoreCacheKey())) {
                return null;
            }

            // If docId == 0 then we a parent doc doesn't have child docs, because child docs are stored
            // before the parent doc and because parent doc is 0 we can safely assume that there are no child docs.
            if (docId == 0) {
                return null;
            }

            final BitSet parents = parentFilter.getBitSet(context);
            final int firstChildDocId = parents.prevSetBit(docId - 1) + 1;
            // A parent doc doesn't have child docs, so we can early exit here:
            if (firstChildDocId == docId) {
                return null;
            }

            final Scorer childrenScorer = childWeight.scorer(context);
            if (childrenScorer == null) {
                return null;
            }
            DocIdSetIterator childrenIterator = childrenScorer.iterator();
            final DocIdSetIterator it = new DocIdSetIterator() {

                int doc = -1;

                @Override
                public int docID() {
                    return doc;
                }

                @Override
                public int nextDoc() throws IOException {
                    return advance(doc + 1);
                }

                @Override
                public int advance(int target) throws IOException {
                    target = Math.max(firstChildDocId, target);
                    if (target >= docId) {
                        // We're outside the child nested scope, so it is done
                        return doc = NO_MORE_DOCS;
                    } else {
                        int advanced = childrenIterator.advance(target);
                        if (advanced >= docId) {
                            // We're outside the child nested scope, so it is done
                            return doc = NO_MORE_DOCS;
                        } else {
                            return doc = advanced;
                        }
                    }
                }

                @Override
                public long cost() {
                    return Math.min(childrenIterator.cost(), docId - firstChildDocId);
                }

            };
            return new ConstantScoreScorer(this, score(), it);
        }
    };
}
项目:Elasticsearch    文件:GeoDistanceRangeQuery.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    final Weight boundingBoxWeight;
    if (boundingBoxFilter != null) {
        boundingBoxWeight = searcher.createNormalizedWeight(boundingBoxFilter, false);
    } else {
        boundingBoxWeight = null;
    }
    return new ConstantScoreWeight(this) {
        @Override
        public Scorer scorer(LeafReaderContext context) throws IOException {
            final DocIdSetIterator approximation;
            if (boundingBoxWeight != null) {
                Scorer s = boundingBoxWeight.scorer(context);
                if (s == null) {
                    // if the approximation does not match anything, we're done
                    return null;
                }
                approximation = s.iterator();
            } else {
                approximation = DocIdSetIterator.all(context.reader().maxDoc());
            }
            final MultiGeoPointValues values = indexFieldData.load(context).getGeoPointValues();
            final TwoPhaseIterator twoPhaseIterator = new TwoPhaseIterator(approximation) {
                @Override
                public boolean matches() throws IOException {
                    final int doc = approximation.docID();
                    values.setDocument(doc);
                    final int length = values.count();
                    for (int i = 0; i < length; i++) {
                        GeoPoint point = values.valueAt(i);
                        if (distanceBoundingCheck.isWithin(point.lat(), point.lon())) {
                            double d = fixedSourceDistance.calculate(point.lat(), point.lon());
                            if (d >= inclusiveLowerPoint && d <= inclusiveUpperPoint) {
                                return true;
                            }
                        }
                    }
                    return false;
                }

                @Override
                public float matchCost() {
                    if (distanceBoundingCheck == GeoDistance.ALWAYS_INSTANCE) {
                        return 0.0f;
                    } else {
                        // TODO: is this right (up to 4 comparisons from GeoDistance.SimpleDistanceBoundingCheck)?
                        return 4.0f;
                    }
                }
            };
            return new ConstantScoreScorer(this, score(), twoPhaseIterator);
        }
    };
}
项目:neo4j-lucene5-index    文件:DocValuesCollectorTest.java   
private Scorer constantScorer( float score )
{
    return new ConstantScoreScorer( null, score, (DocIdSetIterator) null );
}
项目:meresco-lucene    文件:SuggestionNGramKeysFilter.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) {
    return new ConstantScoreWeight(this) {
        @Override
        public Scorer scorer(LeafReaderContext context) throws IOException {
            return new ConstantScoreScorer(this, score(), new DocIdSetIterator() {
                private BinaryDocValues keysDocValues = DocValues.getBinary(context.reader(), keyName);
                private int maxDoc = context.reader().maxDoc();
                int docId = -1;

                @Override
                public int docID() {
                    return this.docId;
                }

                @Override
                public int nextDoc() throws IOException {
                    this.docId++;
                    while (this.docId < this.maxDoc) {
                        String keys = this.keysDocValues.get(this.docId).utf8ToString();
                        for (String key: keys.split("\\|")) {
                            if (keySet.get(Integer.parseInt(key))) {
                                return this.docId;
                            }
                        }
                        this.docId++;
                    }
                    this.docId = DocIdSetIterator.NO_MORE_DOCS;
                    return this.docId;
                }

                @Override
                public int advance(int target) throws IOException {
                    this.docId = target - 1;
                    return nextDoc();
                }

                @Override
                public long cost() {
                    return 1L;
                }
           });
       }
   };
}