Java Code Examples for org.apache.lucene.search.DocIdSetIterator#all()

The following examples show how to use org.apache.lucene.search.DocIdSetIterator#all() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SerializedDVStrategy.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  return new ConstantScoreWeight(this, boost) {
    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      DocIdSetIterator approximation = DocIdSetIterator.all(context.reader().maxDoc());
      TwoPhaseIterator it = predicateValueSource.iterator(context, approximation);
      return new ConstantScoreScorer(this, score(), scoreMode, it);
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return predicateValueSource.isCacheable(ctx);
    }

  };
}
 
Example 2
Source File: ValueSourceScorer.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected ValueSourceScorer(Weight weight, LeafReaderContext readerContext, FunctionValues values) {
  super(weight);
  this.values = values;
  final DocIdSetIterator approximation = DocIdSetIterator.all(readerContext.reader().maxDoc()); // no approximation!
  this.twoPhaseIterator = new TwoPhaseIterator(approximation) {
    @Override
    public boolean matches() throws IOException {
      return ValueSourceScorer.this.matches(approximation.docID());
    }

    @Override
    public float matchCost() {
      return ValueSourceScorer.this.matchCost();
    }
  };
  this.disi = TwoPhaseIterator.asDocIdSetIterator(twoPhaseIterator);
}
 
Example 3
Source File: DerivedExpressionQuery.java    From elasticsearch-learning-to-rank with Apache License 2.0 6 votes vote down vote up
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
    Bindings bindings = new Bindings(){
        @Override
        public DoubleValuesSource getDoubleValuesSource(String name) {
            Double queryParamValue  = queryParamValues.get(name);
            if (queryParamValue != null) {
                return DoubleValuesSource.constant(queryParamValue);
            }
            return new FVDoubleValuesSource(vectorSupplier, features.featureOrdinal(name));
        }
    };

    DocIdSetIterator iterator = DocIdSetIterator.all(context.reader().maxDoc());
    DoubleValuesSource src = expression.getDoubleValuesSource(bindings);
    DoubleValues values = src.getValues(context, null);

    return new DValScorer(this, iterator, values);
}
 
Example 4
Source File: DerivedExpressionQuery.java    From elasticsearch-learning-to-rank with Apache License 2.0 6 votes vote down vote up
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
    if (!scoreMode.needsScores()) {
        // If scores are not needed simply return a constant score on all docs
        return new ConstantScoreWeight(this.query, boost) {
            @Override
            public boolean isCacheable(LeafReaderContext ctx) {
                return true;
            }

            @Override
            public Scorer scorer(LeafReaderContext context) throws IOException {
                return new ConstantScoreScorer(this, score(),
                    scoreMode, DocIdSetIterator.all(context.reader().maxDoc()));
            }
        };
    }

    return new FVWeight(this);
}
 
Example 5
Source File: GenericFunctionQuery.java    From crate with Apache License 2.0 5 votes vote down vote up
FilteredTwoPhaseIterator(LeafReader reader,
                         Input<Boolean> condition,
                         LuceneCollectorExpression[] expressions) {
    super(DocIdSetIterator.all(reader.maxDoc()));
    this.condition = condition;
    this.expressions = expressions;
}
 
Example 6
Source File: ArrayLengthQuery.java    From crate with Apache License 2.0 5 votes vote down vote up
NumTermsPerDocTwoPhaseIterator(LeafReader reader,
                               IntUnaryOperator numTermsOfDoc,
                               IntPredicate matches) {
    super(DocIdSetIterator.all(reader.maxDoc()));
    this.numTermsOfDoc = numTermsOfDoc;
    this.matches = matches;
}
 
Example 7
Source File: ScriptFeature.java    From elasticsearch-learning-to-rank with Apache License 2.0 5 votes vote down vote up
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
    LeafScoreFunction leafScoreFunction = function.getLeafScoreFunction(context);
    DocIdSetIterator iterator = DocIdSetIterator.all(context.reader().maxDoc());
    return new Scorer(this) {
        @Override
        public int docID() {
            return iterator.docID();
        }

        @Override
        public float score() throws IOException {
            return (float) leafScoreFunction.score(iterator.docID(), 0F);
        }

        @Override
        public DocIdSetIterator iterator() {
            return iterator;
        }

        /**
         * Return the maximum score that documents between the last {@code target}
         * that this iterator was {@link #advanceShallow(int) shallow-advanced} to
         * included and {@code upTo} included.
         */
        @Override
        public float getMaxScore(int upTo) throws IOException {
            //TODO??
            return Float.POSITIVE_INFINITY;
        }
    };
}
 
Example 8
Source File: FieldLengthFeature.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public FeatureScorer scorer(LeafReaderContext context) throws IOException {
  NumericDocValues norms = context.reader().getNormValues(field);
  if (norms == null){
    return new ValueFeatureScorer(this, 0f,
        DocIdSetIterator.all(DocIdSetIterator.NO_MORE_DOCS));
  }
  return new FieldLengthFeatureScorer(this, norms);
}
 
Example 9
Source File: ValueFeature.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public FeatureScorer scorer(LeafReaderContext context) throws IOException {
  if(featureValue!=null) {
    return new ValueFeatureScorer(this, featureValue,
        DocIdSetIterator.all(DocIdSetIterator.NO_MORE_DOCS));
  } else {
    return null;
  }
}
 
Example 10
Source File: FunctionMatchQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  DoubleValuesSource vs = source.rewrite(searcher);
  return new ConstantScoreWeight(this, boost) {
    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      DoubleValues values = vs.getValues(context, null);
      DocIdSetIterator approximation = DocIdSetIterator.all(context.reader().maxDoc());
      TwoPhaseIterator twoPhase = new TwoPhaseIterator(approximation) {
        @Override
        public boolean matches() throws IOException {
          return values.advanceExact(approximation.docID()) && filter.test(values.doubleValue());
        }

        @Override
        public float matchCost() {
          return 100; // TODO maybe DoubleValuesSource should have a matchCost?
        }
      };
      return new ConstantScoreScorer(this, score(), scoreMode, twoPhase);
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return source.isCacheable(ctx);
    }

  };
}
 
Example 11
Source File: FunctionQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public AllScorer(LeafReaderContext context, FunctionWeight w, float boost) throws IOException {
  super(w);
  this.weight = w;
  this.boost = boost;
  this.reader = context.reader();
  this.maxDoc = reader.maxDoc();
  iterator = DocIdSetIterator.all(context.reader().maxDoc());
  vals = func.getValues(weight.context, context);
}
 
Example 12
Source File: FieldValueFeature.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public FeatureScorer scorer(LeafReaderContext context) throws IOException {
  return new FieldValueFeatureScorer(this, context,
      DocIdSetIterator.all(DocIdSetIterator.NO_MORE_DOCS));
}
 
Example 13
Source File: DocsWithFieldSet.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public DocIdSetIterator iterator() {
  return set != null ? new BitSetIterator(set, cost) : DocIdSetIterator.all(cost);
}
 
Example 14
Source File: DoubleRange.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  final Weight fastMatchWeight = fastMatchQuery == null
      ? null
      : searcher.createWeight(fastMatchQuery, ScoreMode.COMPLETE_NO_SCORES, 1f);

  return new ConstantScoreWeight(this, boost) {
    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      final int maxDoc = context.reader().maxDoc();

      final DocIdSetIterator approximation;
      if (fastMatchWeight == null) {
        approximation = DocIdSetIterator.all(maxDoc);
      } else {
        Scorer s = fastMatchWeight.scorer(context);
        if (s == null) {
          return null;
        }
        approximation = s.iterator();
      }

      final DoubleValues values = valueSource.getValues(context, null);
      final TwoPhaseIterator twoPhase = new TwoPhaseIterator(approximation) {
        @Override
        public boolean matches() throws IOException {
          return values.advanceExact(approximation.docID()) && range.accept(values.doubleValue());
        }

        @Override
        public float matchCost() {
          return 100; // TODO: use cost of range.accept()
        }
      };
      return new ConstantScoreScorer(this, score(), scoreMode, twoPhase);
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return valueSource.isCacheable(ctx);
    }

  };
}
 
Example 15
Source File: LongRange.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  final Weight fastMatchWeight = fastMatchQuery == null
      ? null
      : searcher.createWeight(fastMatchQuery, ScoreMode.COMPLETE_NO_SCORES, 1f);

  return new ConstantScoreWeight(this, boost) {
    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      final int maxDoc = context.reader().maxDoc();

      final DocIdSetIterator approximation;
      if (fastMatchWeight == null) {
        approximation = DocIdSetIterator.all(maxDoc);
      } else {
        Scorer s = fastMatchWeight.scorer(context);
        if (s == null) {
          return null;
        }
        approximation = s.iterator();
      }

      final LongValues values = valueSource.getValues(context, null);
      final TwoPhaseIterator twoPhase = new TwoPhaseIterator(approximation) {
        @Override
        public boolean matches() throws IOException {
          return values.advanceExact(approximation.docID()) && range.accept(values.longValue());
        }

        @Override
        public float matchCost() {
          return 100; // TODO: use cost of range.accept()
        }
      };
      return new ConstantScoreScorer(this, score(), scoreMode, twoPhase);
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return valueSource.isCacheable(ctx);
    }

  };
}
 
Example 16
Source File: ShardSplittingQuery.java    From crate with Apache License 2.0 4 votes vote down vote up
RoutingPartitionedDocIdSetIterator(Visitor visitor) {
    super(DocIdSetIterator.all(visitor.leafReader.maxDoc())); // we iterate all live-docs
    this.visitor = visitor;
}
 
Example 17
Source File: GeoDistanceRangeQuery.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@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);
        }
    };
}
 
Example 18
Source File: NoopScorer.java    From elasticsearch-learning-to-rank with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a Scorer
 *
 * @param weight The scorers weight
 * @param maxDocs maximum number of documents to score
 */
public NoopScorer(Weight weight, int maxDocs) {
    super(weight);
    _noopIter = DocIdSetIterator.all(maxDocs);

}