List of usage examples for org.apache.lucene.spatial.query SpatialArgs getOperation
public SpatialOperation getOperation()
From source file:org.apache.blur.analysis.type.spatial.BaseSpatialFieldTypeDefinition.java
License:Apache License
protected void checkSpatialArgs(SpatialArgs args) { SpatialOperation operation = args.getOperation(); for (SpatialOperation so : _supportedOperations) { if (operation == so) { return; }/*w ww. j ava 2 s . com*/ } throw new IllegalArgumentException( _strategy.getClass().getName() + " only supports [" + _supportedOperations + "] operation."); }
From source file:org.apache.blur.analysis.type.spatial.lucene.RecursivePrefixTreeStrategy.java
License:Apache License
@Override public Filter makeFilter(SpatialArgs args) { final SpatialOperation op = args.getOperation(); if (op == SpatialOperation.IsDisjointTo) return new DisjointSpatialFilter(this, args, getFieldName()); Shape shape = args.getShape(); int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct)); final boolean hasIndexedLeaves = true; if (op == SpatialOperation.Intersects) { return new IntersectsPrefixTreeFilter(shape, getFieldName(), grid, detailLevel, prefixGridScanLevel, hasIndexedLeaves);//from w ww.j a va2s . co m } else if (op == SpatialOperation.IsWithin) { return new WithinPrefixTreeFilter(shape, getFieldName(), grid, detailLevel, prefixGridScanLevel, -1);// -1 // flag // is // slower // but // ensures // correct // results } else if (op == SpatialOperation.Contains) { return new ContainsPrefixTreeFilter(shape, getFieldName(), grid, detailLevel); } throw new UnsupportedSpatialOperation(op); }
From source file:org.apache.blur.analysis.type.spatial.lucene.TermQueryPrefixTreeStrategy.java
License:Apache License
@Override public Filter makeFilter(SpatialArgs args) { final SpatialOperation op = args.getOperation(); if (op != SpatialOperation.Intersects) throw new UnsupportedSpatialOperation(op); Shape shape = args.getShape(); int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct)); List<Cell> cells = grid.getCells(shape, detailLevel, false, // no parents true);// simplify BytesRef[] terms = new BytesRef[cells.size()]; int i = 0;/*from w w w. j a va2 s.com*/ for (Cell cell : cells) { terms[i++] = new BytesRef(cell.getTokenString()); } return new TermsFilter(getFieldName(), terms); }
From source file:org.apache.blur.analysis.type.spatial.SpatialArgsParser.java
License:Apache License
/** Writes a close approximation to the parsed input format. */ public static String writeSpatialArgs(SpatialArgs args, ShapeReadWriter<SpatialContext> shapeReadWriter) { StringBuilder str = new StringBuilder(); str.append(args.getOperation().getName()); str.append('('); str.append(shapeReadWriter.writeShape(args.getShape())); if (args.getDistErrPct() != null) str.append(" distErrPct=").append(String.format(Locale.ROOT, "%.2f%%", args.getDistErrPct() * 100d)); if (args.getDistErr() != null) str.append(" distErr=").append(args.getDistErr()); str.append(')'); return str.toString(); }
From source file:org.apache.solr.legacy.BBoxStrategy.java
License:Apache License
@Override public Query makeQuery(SpatialArgs args) { Shape shape = args.getShape(); if (!(shape instanceof Rectangle)) throw new UnsupportedOperationException("Can only query by Rectangle, not " + shape); Rectangle bbox = (Rectangle) shape; Query spatial;/*ww w .ja v a 2s . c o m*/ // Useful for understanding Relations: // http://edndoc.esri.com/arcsde/9.1/general_topics/understand_spatial_relations.htm SpatialOperation op = args.getOperation(); if (op == SpatialOperation.BBoxIntersects) spatial = makeIntersects(bbox); else if (op == SpatialOperation.BBoxWithin) spatial = makeWithin(bbox); else if (op == SpatialOperation.Contains) spatial = makeContains(bbox); else if (op == SpatialOperation.Intersects) spatial = makeIntersects(bbox); else if (op == SpatialOperation.IsEqualTo) spatial = makeEquals(bbox); else if (op == SpatialOperation.IsDisjointTo) spatial = makeDisjoint(bbox); else if (op == SpatialOperation.IsWithin) spatial = makeWithin(bbox); else { //no Overlaps support yet throw new UnsupportedSpatialOperation(op); } return new ConstantScoreQuery(spatial); }
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 ww.j av a2 s . com 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 } }