Example usage for org.apache.lucene.queries.function FunctionMatchQuery FunctionMatchQuery

List of usage examples for org.apache.lucene.queries.function FunctionMatchQuery FunctionMatchQuery

Introduction

In this page you can find the example usage for org.apache.lucene.queries.function FunctionMatchQuery FunctionMatchQuery.

Prototype

public FunctionMatchQuery(DoubleValuesSource source, DoublePredicate filter) 

Source Link

Document

Create a FunctionMatchQuery

Usage

From source file:org.apache.solr.legacy.PointVectorStrategy.java

License:Apache License

@Override
public ConstantScoreQuery makeQuery(SpatialArgs args) {
    if (!SpatialOperation.is(args.getOperation(), SpatialOperation.Intersects, SpatialOperation.IsWithin))
        throw new UnsupportedSpatialOperation(args.getOperation());
    Shape shape = args.getShape();
    if (shape instanceof Rectangle) {
        Rectangle bbox = (Rectangle) shape;
        return new ConstantScoreQuery(makeWithin(bbox));
    } else if (shape instanceof Circle) {
        Circle circle = (Circle) shape;/*from w w  w.  j  av  a2  s .  c  o m*/
        Rectangle bbox = circle.getBoundingBox();
        Query approxQuery = makeWithin(bbox);
        BooleanQuery.Builder bqBuilder = new BooleanQuery.Builder();
        double r = circle.getRadius();
        FunctionMatchQuery vsMatchQuery = new FunctionMatchQuery(makeDistanceValueSource(circle.getCenter()),
                v -> 0 <= v && v <= r);
        bqBuilder.add(approxQuery, BooleanClause.Occur.FILTER);//should have lowest "cost" value; will drive iteration
        bqBuilder.add(vsMatchQuery, BooleanClause.Occur.FILTER);
        return new ConstantScoreQuery(bqBuilder.build());
    } else {
        throw new UnsupportedOperationException(
                "Only Rectangles and Circles are currently supported, " + "found [" + shape.getClass() + "]");//TODO
    }
}