org.apache.lucene.search.DoubleValues#advanceExact ( )源码实例Demo

下面列出了org.apache.lucene.search.DoubleValues#advanceExact ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lucene-solr   文件: ValueSource.java
@Override
public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
  Map<Object, Object> context = new IdentityHashMap<>();
  ScoreAndDoc scorer = new ScoreAndDoc();
  context.put("scorer", scorer);
  final FunctionValues fv = in.getValues(context, ctx);
  return new LongValues() {

    @Override
    public long longValue() throws IOException {
      return fv.longVal(scorer.current);
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      scorer.current = doc;
      if (scores != null && scores.advanceExact(doc))
        scorer.score = (float) scores.doubleValue();
      else
        scorer.score = 0;
      return fv.exists(doc);
    }
  };
}
 
源代码2 项目: lucene-solr   文件: FunctionScoreQuery.java
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
  Scorer in = inner.scorer(context);
  if (in == null)
    return null;
  DoubleValues scores = valueSource.getValues(context, DoubleValuesSource.fromScorer(in));
  return new FilterScorer(in) {
    @Override
    public float score() throws IOException {
      if (scores.advanceExact(docID())) {
        double factor = scores.doubleValue();
        if (factor >= 0) {
          return (float) (factor * boost);
        }
      }
      // default: missing value, negative value or NaN
      return 0;
    }
    @Override
    public float getMaxScore(int upTo) throws IOException {
      return Float.POSITIVE_INFINITY;
    }
  };
}
 
源代码3 项目: lucene-solr   文件: ExpressionValueSource.java
private static DoubleValues zeroWhenUnpositioned(DoubleValues in) {
  return new DoubleValues() {

    boolean positioned = false;

    @Override
    public double doubleValue() throws IOException {
      return positioned ? in.doubleValue() : 0;
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return positioned = in.advanceExact(doc);
    }
  };
}
 
源代码4 项目: lucene-solr   文件: TaxonomyFacetSumValueSource.java
private void sumValues(List<MatchingDocs> matchingDocs, boolean keepScores, DoubleValuesSource valueSource) throws IOException {

    IntsRef scratch = new IntsRef();
    for(MatchingDocs hits : matchingDocs) {
      OrdinalsReader.OrdinalsSegmentReader ords = ordinalsReader.getReader(hits.context);
      DoubleValues scores = keepScores ? scores(hits) : null;
      DoubleValues functionValues = valueSource.getValues(hits.context, scores);
      DocIdSetIterator docs = hits.bits.iterator();
      
      int doc;
      while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        ords.get(doc, scratch);
        if (functionValues.advanceExact(doc)) {
          float value = (float) functionValues.doubleValue();
          for (int i = 0; i < scratch.length; i++) {
            values[scratch.ints[i]] += value;
          }
        }
      }
    }

    rollup();
  }
 
源代码5 项目: lucene-solr   文件: BBoxValueSource.java
@Override
public ShapeValues getValues(LeafReaderContext readerContext) throws IOException {

  final DoubleValues minX = DoubleValuesSource.fromDoubleField(strategy.field_minX).getValues(readerContext, null);
  final DoubleValues minY = DoubleValuesSource.fromDoubleField(strategy.field_minY).getValues(readerContext, null);
  final DoubleValues maxX = DoubleValuesSource.fromDoubleField(strategy.field_maxX).getValues(readerContext, null);
  final DoubleValues maxY = DoubleValuesSource.fromDoubleField(strategy.field_maxY).getValues(readerContext, null);

  //reused
  final Rectangle rect = strategy.getSpatialContext().makeRectangle(0,0,0,0);

  return new ShapeValues() {

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return minX.advanceExact(doc) && maxX.advanceExact(doc) && minY.advanceExact(doc) && maxY.advanceExact(doc);
    }

    @Override
    public Shape value() throws IOException {
      rect.reset(minX.doubleValue(), maxX.doubleValue(), minY.doubleValue(), maxY.doubleValue());
      return rect;
    }

  };
}
 
源代码6 项目: lucene-solr   文件: BBoxSimilarityValueSource.java
@Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
  DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue().doubleValue()).getValues(ctx, null));
  if (dv.advanceExact(docId)) {
    AtomicReference<Explanation> explanation = new AtomicReference<>();
    final ShapeValues shapeValues = bboxValueSource.getValues(ctx);
    if (shapeValues.advanceExact(docId)) {
      score((Rectangle) shapeValues.value(), explanation);
      return explanation.get();
    }
  }
  return Explanation.noMatch(this.toString());
}
 
源代码7 项目: lucene-solr   文件: PointVectorStrategy.java
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  Weight w = inner.createWeight(searcher, scoreMode, 1f);
  return new ConstantScoreWeight(this, boost) {
    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      Scorer in = w.scorer(context);
      if (in == null)
        return null;
      DoubleValues v = distanceSource.getValues(context, DoubleValuesSource.fromScorer(in));
      DocIdSetIterator approximation = in.iterator();
      TwoPhaseIterator twoPhase = new TwoPhaseIterator(approximation) {
        @Override
        public boolean matches() throws IOException {
          return v.advanceExact(approximation.docID()) && v.doubleValue() <= limit;
        }

        @Override
        public float matchCost() {
          return 100;   // distance calculation can be heavy!
        }
      };
      return new ConstantScoreScorer(this, score(), scoreMode, twoPhase);
    }

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

  };
}
 
@Override
public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
  DoubleValues in = input.getValues(ctx, scores);
  return new DoubleValues() {
    @Override
    public double doubleValue() throws IOException {
      return recip(in.doubleValue());
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return in.advanceExact(doc);
    }
  };
}
 
源代码9 项目: lucene-solr   文件: ValueSource.java
@Override
public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
  Map<Object, Object> context = new HashMap<>();
  ScoreAndDoc scorer = new ScoreAndDoc();
  context.put("scorer", scorer);
  context.put("searcher", searcher);
  FunctionValues fv = in.getValues(context, ctx);
  return new DoubleValues() {

    @Override
    public double doubleValue() throws IOException {
      return fv.doubleVal(scorer.current);
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      scorer.current = doc;
      if (scores != null && scores.advanceExact(doc)) {
        scorer.score = (float) scores.doubleValue();
      }
      else
        scorer.score = 0;
      // ValueSource will return values even if exists() is false, generally a default
      // of some kind.  To preserve this behaviour with the iterator, we need to always
      // return 'true' here.
      return true;
    }
  };
}
 
源代码10 项目: lucene-solr   文件: FunctionMatchQuery.java
@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);
    }

  };
}
 
源代码11 项目: lucene-solr   文件: FunctionScoreQuery.java
@Override
public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
  DoubleValues in = DoubleValues.withDefault(boost.getValues(ctx, scores), 1);
  return new DoubleValues() {
    @Override
    public double doubleValue() throws IOException {
      return scores.doubleValue() * in.doubleValue();
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return in.advanceExact(doc);
    }
  };
}
 
源代码12 项目: lucene-solr   文件: ExpressionValueSource.java
@Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
  Explanation[] explanations = new Explanation[variables.length];
  DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue().doubleValue()).getValues(ctx, null));
  if (dv.advanceExact(docId) == false) {
    return Explanation.noMatch(expression.sourceText);
  }
  int i = 0;
  for (DoubleValuesSource var : variables) {
    explanations[i++] = var.explain(ctx, docId, scoreExplanation);
  }
  return Explanation.match(dv.doubleValue(), expression.sourceText + ", computed from:", explanations);
}
 
源代码13 项目: lucene-solr   文件: ExpressionFunctionValues.java
@Override
public boolean advanceExact(int doc) throws IOException {
  for (DoubleValues v : functionValues) {
    v.advanceExact(doc);
  }
  return true;
}
 
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
    Bindings bindings = new Bindings(){
        @Override
        public DoubleValuesSource getDoubleValuesSource(String name) {
            return new FVDoubleValuesSource(vectorSupplier, features.featureOrdinal(name));
        }
    };

    DoubleValuesSource src = expression.getDoubleValuesSource(bindings);
    DoubleValues values = src.getValues(context, null);
    values.advanceExact(doc);
    return Explanation.match((float) values.doubleValue(), "Evaluation of derived expression: " + expression.sourceText);
}
 
源代码15 项目: lucene-solr   文件: DoubleRangeFacetCounts.java
private void count(DoubleValuesSource valueSource, List<MatchingDocs> matchingDocs) throws IOException {

    DoubleRange[] ranges = (DoubleRange[]) this.ranges;

    LongRange[] longRanges = new LongRange[ranges.length];
    for(int i=0;i<ranges.length;i++) {
      DoubleRange range = ranges[i];
      longRanges[i] =  new LongRange(range.label,
                                     NumericUtils.doubleToSortableLong(range.min), true,
                                     NumericUtils.doubleToSortableLong(range.max), true);
    }

    LongRangeCounter counter = new LongRangeCounter(longRanges);

    int missingCount = 0;
    for (MatchingDocs hits : matchingDocs) {
      DoubleValues fv = valueSource.getValues(hits.context, null);
      
      totCount += hits.totalHits;
      final DocIdSetIterator fastMatchDocs;
      if (fastMatchQuery != null) {
        final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(hits.context);
        final IndexSearcher searcher = new IndexSearcher(topLevelContext);
        searcher.setQueryCache(null);
        final Weight fastMatchWeight = searcher.createWeight(searcher.rewrite(fastMatchQuery), ScoreMode.COMPLETE_NO_SCORES, 1);
        Scorer s = fastMatchWeight.scorer(hits.context);
        if (s == null) {
          continue;
        }
        fastMatchDocs = s.iterator();
      } else {
        fastMatchDocs = null;
      }

      DocIdSetIterator docs = hits.bits.iterator();

      for (int doc = docs.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; ) {
        if (fastMatchDocs != null) {
          int fastMatchDoc = fastMatchDocs.docID();
          if (fastMatchDoc < doc) {
            fastMatchDoc = fastMatchDocs.advance(doc);
          }

          if (doc != fastMatchDoc) {
            doc = docs.advance(fastMatchDoc);
            continue;
          }
        }
        // Skip missing docs:
        if (fv.advanceExact(doc)) {
          counter.add(NumericUtils.doubleToSortableLong(fv.doubleValue()));
        } else {
          missingCount++;
        }

        doc = docs.nextDoc();
      }
    }

    missingCount += counter.fillCounts(counts);
    totCount -= missingCount;
  }
 
源代码16 项目: lucene-solr   文件: DoubleRange.java
@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);
    }

  };
}