public GeoProperty(Property prop) { this.prop = prop; this.spatialctx = SpatialContext.GEO; int maxlevels = 11; // FIXME: how to compute? GeohashPrefixTree grid = new GeohashPrefixTree(spatialctx, maxlevels); this.strategy = new RecursivePrefixTreeStrategy(grid, prop.getName()); }
private void setupPrefixTrees() { GeoShapeFieldType ft = fieldType(); SpatialPrefixTree prefixTree; if (ft.tree().equals(DeprecatedParameters.PrefixTrees.GEOHASH)) { prefixTree = new GeohashPrefixTree(ShapeBuilder.SPATIAL_CONTEXT, getLevels(ft.treeLevels(), ft.precisionInMeters(), DeprecatedParameters.Defaults.GEOHASH_TREE_LEVELS, true)); } else if (ft.tree().equals(DeprecatedParameters.PrefixTrees.LEGACY_QUADTREE)) { prefixTree = new QuadPrefixTree(ShapeBuilder.SPATIAL_CONTEXT, getLevels(ft.treeLevels(), ft.precisionInMeters(), DeprecatedParameters.Defaults.QUADTREE_LEVELS, false)); } else if (ft.tree().equals(DeprecatedParameters.PrefixTrees.QUADTREE)) { prefixTree = new PackedQuadPrefixTree(ShapeBuilder.SPATIAL_CONTEXT, getLevels(ft.treeLevels(), ft.precisionInMeters(), DeprecatedParameters.Defaults.QUADTREE_LEVELS, false)); } else { throw new IllegalArgumentException("Unknown prefix tree type [" + ft.tree() + "]"); } // setup prefix trees regardless of strategy (this is used for the QueryBuilder) // recursive: RecursivePrefixTreeStrategy rpts = new RecursivePrefixTreeStrategy(prefixTree, ft.name()); rpts.setDistErrPct(ft.distanceErrorPct()); rpts.setPruneLeafyBranches(false); ft.recursiveStrategy = rpts; // term: TermQueryPrefixTreeStrategy termStrategy = new TermQueryPrefixTreeStrategy(prefixTree, ft.name()); termStrategy.setDistErrPct(ft.distanceErrorPct()); ft.termStrategy = termStrategy; // set default (based on strategy): ft.defaultPrefixTreeStrategy = ft.resolvePrefixTreeStrategy(ft.strategy()); ft.defaultPrefixTreeStrategy.setPointsOnly(ft.pointsOnly()); }
private void indexShape(ParseContext context, Shape shape) { List<IndexableField> fields = new ArrayList<>(Arrays.asList(fieldType().defaultPrefixTreeStrategy().createIndexableFields(shape))); createFieldNamesField(context, fields); for (IndexableField field : fields) { context.doc().add(field); } }
public Field[] createIndexableFields(Shape shape, int detailLevel) { //TODO re-use TokenStream LUCENE-5776: Subclass Field, put cell iterator there, override tokenStream() Iterator<Cell> cells = createCellIteratorToIndex(shape, detailLevel, null); CellToBytesRefIterator cellToBytesRefIterator = newCellToBytesRefIterator(); cellToBytesRefIterator.reset(cells); BytesRefIteratorTokenStream tokenStream = new BytesRefIteratorTokenStream(); tokenStream.setBytesRefIterator(cellToBytesRefIterator); Field field = new Field(getFieldName(), tokenStream, FIELD_TYPE); return new Field[]{field}; }
@Override protected void visitLeaf(Cell cell) throws IOException { if (allCellsIntersectQuery(cell)) collectDocs(inside); else collectDocs(outside); }
Query intersects = prefixTreeStrategy.makeQuery(getArgs(shapeToQuery, ShapeRelation.INTERSECTS)); bool.add(exists, BooleanClause.Occur.MUST); bool.add(intersects, BooleanClause.Occur.MUST_NOT); query = new ConstantScoreQuery(bool.build()); } else { query = new ConstantScoreQuery(prefixTreeStrategy.makeQuery(getArgs(shapeToQuery, relation)));
public ContainsVisitor(LeafReaderContext context) throws IOException { super(context); if (termsEnum != null) { nextTerm();//advance to first } }
public CompositeSpatialStrategy(String fieldName, RecursivePrefixTreeStrategy indexStrategy, SerializedDVStrategy geometryStrategy) { super(indexStrategy.getSpatialContext(), fieldName);//field name; unused this.indexStrategy = indexStrategy; this.geometryStrategy = geometryStrategy; }
private SmallDocSet union(SmallDocSet aSet, SmallDocSet bSet) { if (bSet != null) { if (aSet == null) return bSet; return aSet.union(bSet);//union is 'or' } return aSet; }
/** * See {@link AbstractVisitingPrefixTreeQuery#AbstractVisitingPrefixTreeQuery(org.locationtech.spatial4j.shape.Shape, String, org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree, int, int)}. * {@code queryBuffer} is the (minimum) distance beyond the query shape edge * where non-matching documents are looked for so they can be excluded. If * -1 is used then the whole world is examined (a good default for correctness). */ public WithinPrefixTreeQuery(Shape queryShape, String fieldName, SpatialPrefixTree grid, int detailLevel, int prefixGridScanLevel, double queryBuffer) { super(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel); this.bufferedQueryShape = queryBuffer == -1 ? null : bufferShape(queryShape, queryBuffer); }
/** * Computes spatial facets in two dimensions as a grid of numbers. The data is often visualized as a so-called * "heatmap". * * @see HeatmapFacetCounter#calcFacets(PrefixTreeStrategy, IndexReaderContext, Bits, Shape, int, int) */ public HeatmapFacetCounter.Heatmap calcFacets(IndexReaderContext context, Bits topAcceptDocs, Shape inputShape, final int facetLevel, int maxCells) throws IOException { return HeatmapFacetCounter.calcFacets(this, context, topAcceptDocs, inputShape, facetLevel, maxCells); }
@Override public boolean equals(Object o) { if (!super.equals(o)) return false; return multiOverlappingIndexedShapes == ((ContainsPrefixTreeQuery)o).multiOverlappingIndexedShapes; }
@Override public int advance(int target) throws IOException { //for this small set this is likely faster vs. a binary search // into the sorted array return slowAdvance(target); }
@Override protected void visitScanned(Cell cell) throws IOException { visitLeaf(cell);//collects as we want, even if not a leaf // if (cell.isLeaf()) { // visitLeaf(cell); // } else { // visitPrefix(cell); // } }
@Override public Bits bits() throws IOException { //if the # of docids is super small, return null since iteration is going // to be faster return size() > 4 ? this : null; }
/** * A quick check of the shape to see if it is perfectly aligned to a grid. * Points always are as they are indivisible. It's okay to return false * if the shape actually is aligned; this is an optimization hint. */ protected boolean isGridAlignedShape(Shape shape) { return isPointShape(shape); }
public Field[] createIndexableFields(Shape shape, int detailLevel) { //TODO re-use TokenStream LUCENE-5776: Subclass Field, put cell iterator there, override tokenStream() Iterator<Cell> cells = createCellIteratorToIndex(shape, detailLevel, null); CellToBytesRefIterator cellToBytesRefIterator = newCellToBytesRefIterator(); cellToBytesRefIterator.reset(cells); BytesRefIteratorTokenStream tokenStream = new BytesRefIteratorTokenStream(); tokenStream.setBytesRefIterator(cellToBytesRefIterator); Field field = new Field(getFieldName(), tokenStream, FIELD_TYPE); return new Field[]{field}; }
public ContainsVisitor(LeafReaderContext context) throws IOException { super(context); if (termsEnum != null) { nextTerm();//advance to first } }
public CompositeSpatialStrategy(String fieldName, RecursivePrefixTreeStrategy indexStrategy, SerializedDVStrategy geometryStrategy) { super(indexStrategy.getSpatialContext(), fieldName);//field name; unused this.indexStrategy = indexStrategy; this.geometryStrategy = geometryStrategy; }