Search in sources :

Example 1 with RecursivePrefixTreeStrategy

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

the class SpatialRecursivePrefixTreeFieldType method newPrefixTreeStrategy.

@Override
protected RecursivePrefixTreeStrategy newPrefixTreeStrategy(String fieldName) {
    RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, fieldName);
    if (prefixGridScanLevel != null)
        strategy.setPrefixGridScanLevel(prefixGridScanLevel);
    if (grid instanceof PackedQuadPrefixTree) {
        // This grid has a (usually) better prune leafy branch implementation
        ((PackedQuadPrefixTree) grid).setPruneLeafyBranches(true);
        strategy.setPruneLeafyBranches(false);
    }
    return strategy;
}
Also used : RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) PackedQuadPrefixTree(org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree)

Example 2 with RecursivePrefixTreeStrategy

use of org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy 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 3 with RecursivePrefixTreeStrategy

use of org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy 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)

Example 4 with RecursivePrefixTreeStrategy

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

the class SpatialDocMaker method makeRPTStrategy.

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);
        //always leave it to packed grid, even though it isn't the same
        strategy.setPruneLeafyBranches(false);
    } else {
        strategy.setPruneLeafyBranches(pruneLeafyBranches);
    }
    int prefixGridScanLevel = config.get("query.spatial.prefixGridScanLevel", -4);
    if (prefixGridScanLevel < 0)
        prefixGridScanLevel = grid.getMaxLevels() + prefixGridScanLevel;
    strategy.setPrefixGridScanLevel(prefixGridScanLevel);
    //doc & query; a default
    double distErrPct = config.get("spatial.distErrPct", .025);
    strategy.setDistErrPct(distErrPct);
    return strategy;
}
Also used : RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) PackedQuadPrefixTree(org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree) Point(org.locationtech.spatial4j.shape.Point)

Example 5 with RecursivePrefixTreeStrategy

use of org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy in project ddf by codice.

the class TestGeoNamesQueryLuceneIndex method setUp.

@Before
public void setUp() throws IOException {
    directoryIndex = spy(new GeoNamesQueryLuceneDirectoryIndex());
    directoryIndex.setIndexLocation(null);
    final SpatialPrefixTree grid = new GeohashPrefixTree(SPATIAL_CONTEXT, GeoNamesLuceneConstants.GEOHASH_LEVELS);
    strategy = new RecursivePrefixTreeStrategy(grid, GeoNamesLuceneConstants.GEO_FIELD);
    initializeIndex();
    doReturn(directory).when(directoryIndex).openDirectory();
}
Also used : RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree) Before(org.junit.Before)

Aggregations

RecursivePrefixTreeStrategy (org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy)18 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)12 GeohashPrefixTree (org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)11 SpatialStrategy (org.apache.lucene.spatial.SpatialStrategy)6 QuadPrefixTree (org.apache.lucene.spatial.prefix.tree.QuadPrefixTree)4 ArrayList (java.util.ArrayList)3 TermQueryPrefixTreeStrategy (org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy)3 PackedQuadPrefixTree (org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree)3 SerializedDVStrategy (org.apache.lucene.spatial.serialized.SerializedDVStrategy)3 ParametersFactory (com.carrotsearch.randomizedtesting.annotations.ParametersFactory)2 CompositeSpatialStrategy (org.apache.lucene.spatial.composite.CompositeSpatialStrategy)2 PrefixTreeStrategy (org.apache.lucene.spatial.prefix.PrefixTreeStrategy)2 SpatialArgs (org.apache.lucene.spatial.query.SpatialArgs)2 GeoEntry (org.codice.ddf.spatial.geocoding.GeoEntry)2 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)2 Point (org.locationtech.spatial4j.shape.Point)2 IOException (java.io.IOException)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 Supplier (org.apache.logging.log4j.util.Supplier)1 IndexWriter (org.apache.lucene.index.IndexWriter)1