org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree Java Examples
The following examples show how to use
org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpatialDocMaker.java From lucene-solr with Apache License 2.0 | 6 votes |
protected RecursivePrefixTreeStrategy makeRPTStrategy(String spatialField, Config config, Map<String, String> configMap, SpatialContext ctx) { //A factory for the prefix tree grid SpatialPrefixTree grid = SpatialPrefixTreeFactory.makeSPT(configMap, null, ctx); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, spatialField); strategy.setPointsOnly(config.get("spatial.docPointsOnly", false)); final boolean pruneLeafyBranches = config.get("spatial.pruneLeafyBranches", true); if (grid instanceof PackedQuadPrefixTree) { ((PackedQuadPrefixTree) grid).setPruneLeafyBranches(pruneLeafyBranches); strategy.setPruneLeafyBranches(false);//always leave it to packed grid, even though it isn't the same } else { strategy.setPruneLeafyBranches(pruneLeafyBranches); } int prefixGridScanLevel = config.get("query.spatial.prefixGridScanLevel", -4); if (prefixGridScanLevel < 0) prefixGridScanLevel = grid.getMaxLevels() + prefixGridScanLevel; strategy.setPrefixGridScanLevel(prefixGridScanLevel); double distErrPct = config.get("spatial.distErrPct", .025);//doc & query; a default strategy.setDistErrPct(distErrPct); return strategy; }
Example #2
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@Test public void test28() throws ParseException { SpatialContext ctx = SpatialContext.GEO; ShapeReadWriter<SpatialContext> shapeReadWriter = new ShapeReadWriter<SpatialContext>(ctx); int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_KM)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); String writeSpatialArgs = SpatialArgsParser.writeSpatialArgs(args, shapeReadWriter); // This has to be done because of rounding. SpatialArgs spatialArgs = SpatialArgsParser.parse(writeSpatialArgs, shapeReadWriter); Query q1 = sq(strategy.makeQuery(spatialArgs)); Query q = parseSq("a.id_gis:\"" + writeSpatialArgs + "\""); boolean equals = q1.equals(q); assertTrue(equals); }
Example #3
Source File: QueryEqualsHashCodeTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testEqualsHashCode() { switch (random().nextInt(4)) {//0-3 case 0: predicate = SpatialOperation.Contains; break; case 1: predicate = SpatialOperation.IsWithin; break; default: predicate = SpatialOperation.Intersects; break; } final SpatialPrefixTree gridQuad = new QuadPrefixTree(ctx,10); final SpatialPrefixTree gridGeohash = new GeohashPrefixTree(ctx,10); Collection<SpatialStrategy> strategies = new ArrayList<>(); RecursivePrefixTreeStrategy recursive_geohash = new RecursivePrefixTreeStrategy(gridGeohash, "recursive_geohash"); strategies.add(recursive_geohash); strategies.add(new TermQueryPrefixTreeStrategy(gridQuad, "termquery_quad")); strategies.add(PointVectorStrategy.newInstance(ctx, "pointvector")); strategies.add(BBoxStrategy.newInstance(ctx, "bbox")); final SerializedDVStrategy serialized = new SerializedDVStrategy(ctx, "serialized"); strategies.add(serialized); strategies.add(new CompositeSpatialStrategy("composite", recursive_geohash, serialized)); for (SpatialStrategy strategy : strategies) { testEqualsHashcode(strategy); } }
Example #4
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test47() throws ParseException { SpatialContext ctx = SpatialContext.GEO; int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_MI)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); Query q1 = sq(strategy.makeQuery(args)); Query q = parseSq("<a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0m))\">"); boolean equals = q1.equals(q); assertTrue(equals); }
Example #5
Source File: LuceneIndex.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected Function<String, ? extends SpatialStrategy> createSpatialStrategyMapper(Map<String, String> parameters) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); SpatialContext geoContext = SpatialContextFactory.makeSpatialContext(parameters, classLoader); final SpatialPrefixTree spt = SpatialPrefixTreeFactory.makeSPT(parameters, classLoader, geoContext); return new Function<String, SpatialStrategy>() { @Override public SpatialStrategy apply(String field) { return new RecursivePrefixTreeStrategy(spt, GEO_FIELD_PREFIX + field); } }; }
Example #6
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test46() throws ParseException { SpatialContext ctx = SpatialContext.GEO; int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_MI)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); Query q1 = sq(bq(bc_m(strategy.makeQuery(args)), bc(tq("rowid", "12345")))); Query q = parseSq("<+a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0m))\" rowid:12345>"); boolean equals = q1.equals(q); assertTrue(equals); }
Example #7
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test45() throws ParseException { SpatialContext ctx = SpatialContext.GEO; int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_MI)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); Query q1 = sq(bq(bc_m(strategy.makeQuery(args)))); Query q = parseSq("<+a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0m))\">"); boolean equals = q1.equals(q); assertTrue(equals); }
Example #8
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test30() throws ParseException { SpatialContext ctx = SpatialContext.GEO; int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_MI)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); Query q1 = sq(strategy.makeQuery(args)); Query q = parseSq("a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0m))\""); boolean equals = q1.equals(q); assertTrue(equals); }
Example #9
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test29() throws ParseException { SpatialContext ctx = SpatialContext.GEO; int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_KM)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); Query q1 = sq(strategy.makeQuery(args)); Query q = parseSq("a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0km))\""); boolean equals = q1.equals(q); assertTrue(equals); }
Example #10
Source File: OLuceneSpatialIndexManager.java From orientdb-lucene with Apache License 2.0 | 5 votes |
public OLuceneSpatialIndexManager(OShapeFactory factory) { super(); this.ctx = SpatialContext.GEO; this.factory = factory; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, 11); this.strategy = new RecursivePrefixTreeStrategy(grid, "location"); }
Example #11
Source File: SpatialExample.java From lucene-solr with Apache License 2.0 | 5 votes |
protected void init() { //Typical geospatial context // These can also be constructed from SpatialContextFactory this.ctx = SpatialContext.GEO; int maxLevels = 11;//results in sub-meter precision for geohash //TODO demo lookup by detail distance // This can also be constructed from SpatialPrefixTreeFactory SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); this.strategy = new RecursivePrefixTreeStrategy(grid, "myGeoField"); this.directory = new ByteBuffersDirectory(); }
Example #12
Source File: JtsPolygonTest.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * A PrefixTree pruning optimization gone bad. * See <a href="https://issues.apache.org/jira/browse/LUCENE-4770">LUCENE-4770</a>. */ @Test public void testBadPrefixTreePrune() throws Exception { Shape area = ctx.readShapeFromWkt("POLYGON((-122.83 48.57, -122.77 48.56, -122.79 48.53, -122.83 48.57))"); SpatialPrefixTree trie = new QuadPrefixTree(ctx, 12); TermQueryPrefixTreeStrategy strategy = new TermQueryPrefixTreeStrategy(trie, "geo"); Document doc = new Document(); doc.add(new TextField("id", "1", Store.YES)); Field[] fields = strategy.createIndexableFields(area, 0.025); for (Field field : fields) { doc.add(field); } addDocument(doc); Point upperleft = ctx.getShapeFactory().pointXY(-122.88, 48.54); Point lowerright = ctx.getShapeFactory().pointXY(-122.82, 48.62); Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, ctx.getShapeFactory().rect(upperleft, lowerright))); commit(); TopDocs search = indexSearcher.search(query, 10); ScoreDoc[] scoreDocs = search.scoreDocs; for (ScoreDoc scoreDoc : scoreDocs) { System.out.println(indexSearcher.doc(scoreDoc.doc)); } assertEquals(1, search.totalHits.value); }
Example #13
Source File: WithinPrefixTreeQuery.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * 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); }
Example #14
Source File: IntersectsRPTVerifyQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
public IntersectsRPTVerifyQuery(Shape queryShape, String fieldName, SpatialPrefixTree grid, int detailLevel, int prefixGridScanLevel, ShapeValuesPredicate predicateValueSource) { this.predicateValueSource = predicateValueSource; this.intersectsDiffQuery = new IntersectsDifferentiatingQuery(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel); }
Example #15
Source File: IntersectsRPTVerifyQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
public IntersectsDifferentiatingQuery(Shape queryShape, String fieldName, SpatialPrefixTree grid, int detailLevel, int prefixGridScanLevel) { super(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel); }
Example #16
Source File: PrefixTreeStrategy.java From lucene-solr with Apache License 2.0 | 4 votes |
public SpatialPrefixTree getGrid() { return grid; }
Example #17
Source File: PrefixTreeStrategy.java From lucene-solr with Apache License 2.0 | 4 votes |
public PrefixTreeStrategy(SpatialPrefixTree grid, String fieldName) { super(grid.getSpatialContext(), fieldName); this.grid = grid; }
Example #18
Source File: TermQueryPrefixTreeStrategy.java From lucene-solr with Apache License 2.0 | 4 votes |
public TermQueryPrefixTreeStrategy(SpatialPrefixTree grid, String fieldName) { super(grid, fieldName); }
Example #19
Source File: RecursivePrefixTreeStrategy.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
public RecursivePrefixTreeStrategy(SpatialPrefixTree grid, String fieldName, boolean docValue) { super(grid, fieldName, true, docValue);// simplify indexed cells prefixGridScanLevel = grid.getMaxLevels() - 4;// TODO this default constant // is dependent on the prefix // grid size }
Example #20
Source File: TermQueryPrefixTreeStrategy.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
public TermQueryPrefixTreeStrategy(SpatialPrefixTree grid, String fieldName, boolean docValue) { super(grid, fieldName, false, docValue);// do not simplify indexed cells }
Example #21
Source File: PrefixTreeStrategy.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
public PrefixTreeStrategy(SpatialPrefixTree grid, String fieldName, boolean simplifyIndexedCells, boolean docValue) { super(grid.getSpatialContext(), fieldName); this.grid = grid; this.simplifyIndexedCells = simplifyIndexedCells; this.docValue = docValue; }
Example #22
Source File: PrefixTreeStrategy.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
public SpatialPrefixTree getGrid() { return grid; }
Example #23
Source File: IntersectsPrefixTreeQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
public IntersectsPrefixTreeQuery(Shape queryShape, String fieldName, SpatialPrefixTree grid, int detailLevel, int prefixGridScanLevel) { super(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel); }
Example #24
Source File: PointPrefixTreeFieldCacheProvider.java From lucene-solr with Apache License 2.0 | 4 votes |
public PointPrefixTreeFieldCacheProvider(SpatialPrefixTree grid, String shapeField, int defaultSize) { super( shapeField, defaultSize ); this.grid = grid; }
Example #25
Source File: ContainsPrefixTreeQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
public ContainsPrefixTreeQuery(Shape queryShape, String fieldName, SpatialPrefixTree grid, int detailLevel, boolean multiOverlappingIndexedShapes) { super(queryShape, fieldName, grid, detailLevel); this.multiOverlappingIndexedShapes = multiOverlappingIndexedShapes; }
Example #26
Source File: AbstractPrefixTreeQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
public AbstractPrefixTreeQuery(Shape queryShape, String fieldName, SpatialPrefixTree grid, int detailLevel) { this.queryShape = queryShape; this.fieldName = fieldName; this.grid = grid; this.detailLevel = detailLevel; }
Example #27
Source File: RecursivePrefixTreeStrategy.java From lucene-solr with Apache License 2.0 | 4 votes |
public RecursivePrefixTreeStrategy(SpatialPrefixTree grid, String fieldName) { super(grid, fieldName); prefixGridScanLevel = grid.getMaxLevels() - 4;//TODO this default constant is dependent on the prefix grid size }
Example #28
Source File: AbstractVisitingPrefixTreeQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
public AbstractVisitingPrefixTreeQuery(Shape queryShape, String fieldName, SpatialPrefixTree grid, int detailLevel, int prefixGridScanLevel) { super(queryShape, fieldName, grid, detailLevel); this.prefixGridScanLevel = Math.max(0, Math.min(prefixGridScanLevel, grid.getMaxLevels() - 1)); assert detailLevel <= grid.getMaxLevels(); }