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);
}
}
}
}
}
}
}
}
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);
}
}
}
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);
}
};
}
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);
}
};
}
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);
}
};
}
Aggregations