Java Code Examples for org.apache.lucene.search.DoubleValues#withDefault()

The following examples show how to use org.apache.lucene.search.DoubleValues#withDefault() . 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: BBoxSimilarityValueSource.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public DoubleValues getValues(LeafReaderContext readerContext, DoubleValues scores) throws IOException {

  final ShapeValues shapeValues = bboxValueSource.getValues(readerContext);
  return DoubleValues.withDefault(new DoubleValues() {
    @Override
    public double doubleValue() throws IOException {
      return score((Rectangle) shapeValues.value(), null);
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return shapeValues.advanceExact(doc);
    }
  }, 0);

}
 
Example 2
Source File: DistanceToShapeValueSource.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public DoubleValues getValues(LeafReaderContext readerContext, DoubleValues scores) throws IOException {

  final ShapeValues shapeValues = shapeValueSource.getValues(readerContext);

  return DoubleValues.withDefault(new DoubleValues() {
    @Override
    public double doubleValue() throws IOException {
      return distCalc.distance(queryPoint, shapeValues.value().getCenter()) * multiplier;
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return shapeValues.advanceExact(doc);
    }
  }, nullValue);
}
 
Example 3
Source File: DistanceValueSource.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the FunctionValues used by the function query.
 */
@Override
public DoubleValues getValues(LeafReaderContext readerContext, DoubleValues scores) throws IOException {

  final DoubleValues ptX = DoubleValuesSource.fromDoubleField(strategy.getFieldNameX()).getValues(readerContext, null);
  final DoubleValues ptY = DoubleValuesSource.fromDoubleField(strategy.getFieldNameY()).getValues(readerContext, null);
  final DistanceCalculator calculator = strategy.getSpatialContext().getDistCalc();

  return DoubleValues.withDefault(new DoubleValues() {

    @Override
    public double doubleValue() throws IOException {
      return calculator.distance(from, ptX.doubleValue(), ptY.doubleValue()) * multiplier;
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return ptX.advanceExact(doc) && ptY.advanceExact(doc);
    }
  }, nullValue);

}
 
Example 4
Source File: DistanceValueSource.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the FunctionValues used by the function query.
 */
@Override
public DoubleValues getValues(LeafReaderContext readerContext, DoubleValues scores) throws IOException {
  LeafReader reader = readerContext.reader();

  final NumericDocValues ptX = DocValues.getNumeric(reader, strategy.getFieldNameX());
  final NumericDocValues ptY = DocValues.getNumeric(reader, strategy.getFieldNameY());

  return DoubleValues.withDefault(new DoubleValues() {

    private final Point from = DistanceValueSource.this.from;
    private final DistanceCalculator calculator = strategy.getSpatialContext().getDistCalc();

    @Override
    public double doubleValue() throws IOException {
      double x = Double.longBitsToDouble(ptX.longValue());
      double y = Double.longBitsToDouble(ptY.longValue());
      return calculator.distance(from, x, y) * multiplier;
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return ptX.advanceExact(doc) && ptY.advanceExact(doc);
    }

  }, nullValue);
}
 
Example 5
Source File: ShapeFieldCacheDistanceValueSource.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public DoubleValues getValues(LeafReaderContext readerContext, DoubleValues scores) throws IOException {

  final double nullValue = (ctx.isGeo() ? 180 * multiplier : Double.MAX_VALUE);

  return DoubleValues.withDefault(new DoubleValues() {
    private final ShapeFieldCache<Point> cache =
        provider.getCache(readerContext.reader());
    private final Point from = ShapeFieldCacheDistanceValueSource.this.from;
    private final DistanceCalculator calculator = ctx.getDistCalc();

    private List<Point> currentVals;

    @Override
    public double doubleValue() throws IOException {
      double v = calculator.distance(from, currentVals.get(0));
      for (int i = 1; i < currentVals.size(); i++) {
        v = Math.min(v, calculator.distance(from, currentVals.get(i)));
      }
      return v * multiplier;
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      currentVals = cache.getShapes(doc);
      return currentVals != null;
    }
  }, nullValue);
}
 
Example 6
Source File: ShapeAreaValueSource.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public DoubleValues getValues(LeafReaderContext readerContext, DoubleValues scores) throws IOException {
  final ShapeValues shapeValues = shapeValueSource.getValues(readerContext);
  return DoubleValues.withDefault(new DoubleValues() {
    @Override
    public double doubleValue() throws IOException {
      return shapeValues.value().getArea(geoArea ? ctx : null) * multiplier;
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return shapeValues.advanceExact(doc);
    }
  }, 0);
}
 
Example 7
Source File: FunctionScoreQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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);
    }
  };
}
 
Example 8
Source File: FunctionScoreQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
  DoubleValues in = query.getValues(ctx, null);
  return DoubleValues.withDefault(new DoubleValues() {
    @Override
    public double doubleValue() {
      return boost;
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return in.advanceExact(doc);
    }
  }, 1);
}