Search in sources :

Example 1 with GeohashPrefixTree

use of org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree in project lucene-solr by apache.

the class TestRecursivePrefixTreeStrategy method init.

//Tests should call this first.
private void init(int maxLength) {
    this.maxLength = maxLength;
    this.ctx = SpatialContext.GEO;
    GeohashPrefixTree grid = new GeohashPrefixTree(ctx, maxLength);
    this.strategy = new RecursivePrefixTreeStrategy(grid, getClass().getSimpleName());
}
Also used : GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)

Example 2 with GeohashPrefixTree

use of org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree in project lucene-solr by apache.

the class TestRecursivePrefixTreeStrategy method testOneMeterPrecision.

@Test
public void testOneMeterPrecision() {
    init(GeohashPrefixTree.getMaxLevelsPossible());
    GeohashPrefixTree grid = (GeohashPrefixTree) ((RecursivePrefixTreeStrategy) strategy).getGrid();
    //DWS: I know this to be true.  11 is needed for one meter
    double degrees = DistanceUtils.dist2Degrees(0.001, DistanceUtils.EARTH_MEAN_RADIUS_KM);
    assertEquals(11, grid.getLevelForDistance(degrees));
}
Also used : GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree) Test(org.junit.Test)

Example 3 with GeohashPrefixTree

use of org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree in project lucene-solr by apache.

the class CompositeStrategyTest method setupGeohashGrid.

private void setupGeohashGrid(int maxLevels) {
    this.ctx = SpatialContext.GEO;
    //A fairly shallow grid
    if (maxLevels == -1)
        //max 16k cells (32^3)
        maxLevels = randomIntBetween(1, 3);
    this.grid = new GeohashPrefixTree(ctx, maxLevels);
    this.rptStrategy = newRPT();
}
Also used : GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)

Example 4 with GeohashPrefixTree

use of org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree in project lucene-solr by apache.

the class SpatialExample method init.

protected void init() {
    //Typical geospatial context
    //  These can also be constructed from SpatialContextFactory
    this.ctx = SpatialContext.GEO;
    //results in sub-meter precision for geohash
    int maxLevels = 11;
    //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 RAMDirectory();
}
Also used : RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) Point(org.locationtech.spatial4j.shape.Point) RAMDirectory(org.apache.lucene.store.RAMDirectory) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)

Example 5 with GeohashPrefixTree

use of org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree in project lucene-solr by apache.

the class DistanceStrategyTest method parameters.

@ParametersFactory(argumentFormatting = "strategy=%s")
public static Iterable<Object[]> parameters() {
    List<Object[]> ctorArgs = new ArrayList<>();
    SpatialContext ctx = SpatialContext.GEO;
    SpatialPrefixTree grid;
    SpatialStrategy strategy;
    grid = new QuadPrefixTree(ctx, 25);
    strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    grid = new GeohashPrefixTree(ctx, 12);
    strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    grid = new PackedQuadPrefixTree(ctx, 25);
    strategy = new RecursivePrefixTreeStrategy(grid, "recursive_packedquad");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    strategy = PointVectorStrategy.newInstance(ctx, "pointvector");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    //  Can't test this without un-inverting since PVS legacy config didn't have docValues.
    //    However, note that Solr's tests use UninvertingReader and thus test this.
    //    strategy = PointVectorStrategy.newLegacyInstance(ctx, "pointvector_legacy");
    //    ctorArgs.add(new Object[]{strategy.getFieldName(), strategy});
    strategy = BBoxStrategy.newInstance(ctx, "bbox");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    strategy = new SerializedDVStrategy(ctx, "serialized");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    return ctorArgs;
}
Also used : SpatialContext(org.locationtech.spatial4j.context.SpatialContext) PackedQuadPrefixTree(org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) ArrayList(java.util.ArrayList) RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) TermQueryPrefixTreeStrategy(org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy) PackedQuadPrefixTree(org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree) SerializedDVStrategy(org.apache.lucene.spatial.serialized.SerializedDVStrategy) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree) ParametersFactory(com.carrotsearch.randomizedtesting.annotations.ParametersFactory)

Aggregations

GeohashPrefixTree (org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)17 RecursivePrefixTreeStrategy (org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy)11 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)10 SpatialStrategy (org.apache.lucene.spatial.SpatialStrategy)5 QuadPrefixTree (org.apache.lucene.spatial.prefix.tree.QuadPrefixTree)4 ArrayList (java.util.ArrayList)3 TermQueryPrefixTreeStrategy (org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy)3 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)3 ParametersFactory (com.carrotsearch.randomizedtesting.annotations.ParametersFactory)2 SpatialArgs (org.apache.lucene.spatial.query.SpatialArgs)2 SerializedDVStrategy (org.apache.lucene.spatial.serialized.SerializedDVStrategy)2 GeoEntry (org.codice.ddf.spatial.geocoding.GeoEntry)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 Supplier (org.apache.logging.log4j.util.Supplier)1 DoublePoint (org.apache.lucene.document.DoublePoint)1 LongPoint (org.apache.lucene.document.LongPoint)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 CompositeSpatialStrategy (org.apache.lucene.spatial.composite.CompositeSpatialStrategy)1