List of usage examples for org.apache.lucene.spatial.query SpatialArgs getShape
public Shape getShape()
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 w w.ja v a 2 s . c o 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;// www .j a va 2 s . c om 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;/*from w w w . j a v a 2 s . 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 ww w . j a va2s .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 } }
From source file:org.apache.solr.schema.AbstractSpatialFieldType.java
License:Apache License
private Query getQueryFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs) { T strategy = getStrategy(field.getName()); SolrParams localParams = parser.getLocalParams(); String score = (localParams == null ? null : localParams.get(SCORE_PARAM)); if (score == null || "none".equals(score) || "".equals(score)) { //FYI Solr FieldType doesn't have a getFilter(). We'll always grab // getQuery() but it's possible a strategy has a more efficient getFilter // that could be wrapped -- no way to know. //See SOLR-2883 needScore return strategy.makeQuery(spatialArgs); //ConstantScoreQuery }/* w w w. jav a 2 s .com*/ //We get the valueSource for the score then the filter and combine them. ValueSource valueSource; if ("distance".equals(score)) { double multiplier = 1.0;//TODO support units=kilometers valueSource = strategy.makeDistanceValueSource(spatialArgs.getShape().getCenter(), multiplier); } else if ("recipDistance".equals(score)) { valueSource = strategy.makeRecipDistanceValueSource(spatialArgs.getShape()); } else { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'score' local-param must be one of 'none', 'distance', or 'recipDistance'"); } FunctionQuery functionQuery = new FunctionQuery(valueSource); if (localParams != null && !localParams.getBool(FILTER_PARAM, true)) return functionQuery; Filter filter = strategy.makeFilter(spatialArgs); return new FilteredQuery(functionQuery, filter); }
From source file:org.apache.solr.schema.BBoxField.java
License:Apache License
@Override protected ValueSource getValueSourceFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs, String scoreParam, BBoxStrategy strategy) { if (scoreParam == null) { return null; }/* w w w. j a v a 2s . c om*/ switch (scoreParam) { //TODO move these to superclass after LUCENE-5804 ? case OVERLAP_RATIO: double queryTargetProportion = 0.25;//Suggested default; weights towards target area String v = parser.getParam(PARAM_QUERY_TARGET_PROPORTION); if (v != null) queryTargetProportion = Double.parseDouble(v); double minSideLength = 0.0; v = parser.getParam(PARAM_MIN_SIDE_LENGTH); if (v != null) minSideLength = Double.parseDouble(v); return new BBoxOverlapRatioValueSource(strategy.makeShapeValueSource(), ctx.isGeo(), (Rectangle) spatialArgs.getShape(), queryTargetProportion, minSideLength); case AREA: return new ShapeAreaValueSource(strategy.makeShapeValueSource(), ctx, ctx.isGeo()); case AREA2D: return new ShapeAreaValueSource(strategy.makeShapeValueSource(), ctx, false); default: return super.getValueSourceFromSpatialArgs(parser, field, spatialArgs, scoreParam, strategy); } }