@Override public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { LongValues v = inner.getValues(ctx, scores); return new DoubleValues() { @Override public double doubleValue() throws IOException { return (double) v.longValue(); } @Override public boolean advanceExact(int doc) throws IOException { return v.advanceExact(doc); } }; }
@Override public void setScorer(Scorer scorer) throws IOException { holder.values = producer.getValues(ctx, DoubleValuesSource.fromScorer(scorer)); } };
@Override public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { LongValues v = inner.getValues(ctx, scores); return new DoubleValues() { @Override public double doubleValue() throws IOException { return (double) v.longValue(); } @Override public boolean advanceExact(int doc) throws IOException { return v.advanceExact(doc); } }; }
@Override public void setScorer(Scorer scorer) throws IOException { holder.values = producer.getValues(ctx, DoubleValuesSource.fromScorer(scorer)); } };
@Override public Scorer scorer(LeafReaderContext context) throws IOException { Collection<Scorer> scorers = new ArrayList<>(); for (Weight w : weights) { Scorer s = w.scorer(context); if (s != null) { scorers.add(s); } } if (scorers.isEmpty()) { return null; } return new CoveringScorer(this, scorers, minimumNumberMatch.getValues(context, null), context.reader().maxDoc()); }
@Override public Matches matches(LeafReaderContext context, int doc) throws IOException { LongValues minMatchValues = minimumNumberMatch.getValues(context, null); if (minMatchValues.advanceExact(doc) == false) { return null; } final long minimumNumberMatch = Math.max(1, minMatchValues.longValue()); long matchCount = 0; List<Matches> subMatches = new ArrayList<>(); for (Weight weight : weights) { Matches matches = weight.matches(context, doc); if (matches != null) { matchCount++; subMatches.add(matches); } } if (matchCount < minimumNumberMatch) { return null; } return MatchesUtils.fromSubMatches(subMatches); }
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { LongValues minMatchValues = minimumNumberMatch.getValues(context, null); if (minMatchValues.advanceExact(doc) == false) { return Explanation.noMatch("minimumNumberMatch has no value on the current document"); } final long minimumNumberMatch = Math.max(1, minMatchValues.longValue()); int freq = 0; double score = 0; List<Explanation> subExpls = new ArrayList<>(); for (Weight weight : weights) { Explanation subExpl = weight.explain(context, doc); if (subExpl.isMatch()) { freq++; score += subExpl.getValue(); } subExpls.add(subExpl); } if (freq >= minimumNumberMatch) { return Explanation.match((float) score, freq + " matches for " + minimumNumberMatch + " required matches, sum of:", subExpls); } else { return Explanation.noMatch(freq + " matches for " + minimumNumberMatch + " required matches", subExpls); } }
private void countAll(LongValuesSource valueSource, String field, IndexReader reader) throws IOException { for (LeafReaderContext context : reader.leaves()) { LongValues fv = valueSource.getValues(context, null); int maxDoc = context.reader().maxDoc(); for (int doc = 0; doc < maxDoc; doc++) { // Skip missing docs: if (fv.advanceExact(doc)) { increment(fv.longValue()); totCount++; } } } }
private void count(LongValuesSource valueSource, List<MatchingDocs> matchingDocs) throws IOException { for (MatchingDocs hits : matchingDocs) { LongValues fv = valueSource.getValues(hits.context, null); // NOTE: this is not as efficient as working directly with the doc values APIs in the sparse case // because we are doing a linear scan across all hits, but this API is more flexible since a // LongValuesSource can compute interesting values at query time DocIdSetIterator docs = hits.bits.iterator(); for (int doc = docs.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS;) { // Skip missing docs: if (fv.advanceExact(doc)) { increment(fv.longValue()); totCount++; } doc = docs.nextDoc(); } } }
@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(), twoPhase); }
LongValues fv = valueSource.getValues(hits.context, null);