Search in sources :

Example 1 with ShapePredicateValueSource

use of org.apache.lucene.spatial.util.ShapePredicateValueSource in project lucene-solr by apache.

the class CompositeSpatialStrategy method makeQuery.

@Override
public Query makeQuery(SpatialArgs args) {
    final SpatialOperation pred = args.getOperation();
    if (pred == SpatialOperation.BBoxIntersects || pred == SpatialOperation.BBoxWithin) {
        throw new UnsupportedSpatialOperation(pred);
    }
    if (pred == SpatialOperation.IsDisjointTo) {
        // update class docs when it's added.
        throw new UnsupportedSpatialOperation(pred);
    }
    final ShapePredicateValueSource predicateValueSource = new ShapePredicateValueSource(geometryStrategy.makeShapeValueSource(), pred, args.getShape());
    //System.out.println("PredOpt: " + optimizePredicates);
    if (pred == SpatialOperation.Intersects && optimizePredicates) {
        // We have a smart Intersects impl
        final SpatialPrefixTree grid = indexStrategy.getGrid();
        //default to max precision
        final int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, 0.0));
        return new IntersectsRPTVerifyQuery(args.getShape(), indexStrategy.getFieldName(), grid, detailLevel, indexStrategy.getPrefixGridScanLevel(), predicateValueSource);
    } else {
        //The general path; all index matches get verified
        SpatialArgs indexArgs;
        if (pred == SpatialOperation.Contains) {
            // note: we could map IsWithin as well but it's pretty darned slow since it touches all world grids
            indexArgs = args;
        } else {
            //TODO add args.clone method with new predicate? Or simply make non-final?
            indexArgs = new SpatialArgs(SpatialOperation.Intersects, args.getShape());
            indexArgs.setDistErr(args.getDistErr());
            indexArgs.setDistErrPct(args.getDistErrPct());
        }
        if (indexArgs.getDistErr() == null && indexArgs.getDistErrPct() == null) {
            indexArgs.setDistErrPct(0.10);
        }
        final Query indexQuery = indexStrategy.makeQuery(indexArgs);
        return new CompositeVerifyQuery(indexQuery, predicateValueSource);
    }
}
Also used : UnsupportedSpatialOperation(org.apache.lucene.spatial.query.UnsupportedSpatialOperation) SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) Query(org.apache.lucene.search.Query) ShapePredicateValueSource(org.apache.lucene.spatial.util.ShapePredicateValueSource) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) UnsupportedSpatialOperation(org.apache.lucene.spatial.query.UnsupportedSpatialOperation) SpatialOperation(org.apache.lucene.spatial.query.SpatialOperation) Point(org.locationtech.spatial4j.shape.Point)

Example 2 with ShapePredicateValueSource

use of org.apache.lucene.spatial.util.ShapePredicateValueSource in project lucene-solr by apache.

the class SerializedDVStrategy method makeQuery.

/**
   * Returns a Query that should be used in a random-access fashion.
   * Use in another manner will be SLOW.
   */
@Override
public Query makeQuery(SpatialArgs args) {
    ValueSource shapeValueSource = makeShapeValueSource();
    ShapePredicateValueSource predicateValueSource = new ShapePredicateValueSource(shapeValueSource, args.getOperation(), args.getShape());
    return new PredicateValueSourceQuery(predicateValueSource);
}
Also used : ShapePredicateValueSource(org.apache.lucene.spatial.util.ShapePredicateValueSource) ShapePredicateValueSource(org.apache.lucene.spatial.util.ShapePredicateValueSource) DistanceToShapeValueSource(org.apache.lucene.spatial.util.DistanceToShapeValueSource) ValueSource(org.apache.lucene.queries.function.ValueSource)

Aggregations

ShapePredicateValueSource (org.apache.lucene.spatial.util.ShapePredicateValueSource)2 ValueSource (org.apache.lucene.queries.function.ValueSource)1 Query (org.apache.lucene.search.Query)1 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)1 SpatialArgs (org.apache.lucene.spatial.query.SpatialArgs)1 SpatialOperation (org.apache.lucene.spatial.query.SpatialOperation)1 UnsupportedSpatialOperation (org.apache.lucene.spatial.query.UnsupportedSpatialOperation)1 DistanceToShapeValueSource (org.apache.lucene.spatial.util.DistanceToShapeValueSource)1 Point (org.locationtech.spatial4j.shape.Point)1