Example usage for org.apache.lucene.spatial.prefix RecursivePrefixTreeStrategy setDistErrPct

List of usage examples for org.apache.lucene.spatial.prefix RecursivePrefixTreeStrategy setDistErrPct

Introduction

In this page you can find the example usage for org.apache.lucene.spatial.prefix RecursivePrefixTreeStrategy setDistErrPct.

Prototype

public void setDistErrPct(double distErrPct) 

Source Link

Document

The default measure of shape precision affecting shapes at index and query times.

Usage

From source file:com.orientechnologies.spatial.factory.OSpatialStrategyFactory.java

License:Apache License

public SpatialStrategy createStrategy(SpatialContext ctx, ODatabaseDocumentInternal db,
        OIndexDefinition indexDefinition, ODocument metadata) {

    SpatialStrategy strategy;//w ww .j a  v a  2 s  .co m

    OClass aClass = db.getMetadata().getSchema().getClass(indexDefinition.getClassName());

    OProperty property = aClass.getProperty(indexDefinition.getFields().get(0));

    OClass linkedClass = property.getLinkedClass();

    if ("OPoint".equalsIgnoreCase(linkedClass.getName())) {
        RecursivePrefixTreeStrategy recursivePrefixTreeStrategy = new RecursivePrefixTreeStrategy(
                new GeohashPrefixTree(ctx, 11), "location");
        recursivePrefixTreeStrategy.setDistErrPct(0);
        strategy = recursivePrefixTreeStrategy;

    } else {
        strategy = new BBoxStrategy(ctx, "location");
    }
    return strategy;
}

From source file:com.orientechnologies.spatial.sandbox.LuceneGeoTest.java

License:Apache License

@Test
public void geoIntersectTest() throws IOException, ParseException {

    RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(
            new GeohashPrefixTree(JtsSpatialContext.GEO, 11), "location");

    strategy.setDistErrPct(0);

    IndexWriterConfig conf = new IndexWriterConfig(new StandardAnalyzer());
    final RAMDirectory directory = new RAMDirectory();
    final IndexWriter writer = new IndexWriter(directory, conf);

    Shape point = JtsSpatialContext.GEO.getWktShapeParser().parse("POINT (9.4714708 47.6819432)");

    Shape polygon = JtsSpatialContext.GEO.getWktShapeParser().parse(
            "POLYGON((9.481201171875 47.64885294675266,9.471416473388672 47.65128140482982,9.462661743164062 47.64781214443791,9.449443817138672 47.656947367880335,9.445838928222656 47.66110972448931,9.455795288085938 47.667352637215,9.469013214111328 47.67255449415724,9.477081298828125 47.679142768657066,9.490299224853516 47.678680460743834,9.506263732910156 47.679258344995326,9.51364517211914 47.68191653011071,9.518795013427734 47.677177931734406,9.526691436767578 47.679489496903706,9.53390121459961 47.67139857075435,9.50918197631836 47.66180341832901,9.50815200805664 47.6529003141482,9.51192855834961 47.64654002455372,9.504375457763672 47.64237650648966,9.49270248413086 47.649662445325035,9.48617935180664 47.65151268066222,9.481201171875 47.64885294675266))");

    Document doc = new Document();

    Assert.assertNotEquals(point.relate(polygon), SpatialRelation.INTERSECTS);
    for (IndexableField f : strategy.createIndexableFields(point)) {
        doc.add(f);//ww  w.  ja v  a  2s.co  m
    }

    writer.addDocument(doc);
    writer.commit();

    SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, polygon.getBoundingBox());
    Filter filter = strategy.makeFilter(args);
    IndexReader reader = DirectoryReader.open(directory);

    IndexSearcher searcher = new IndexSearcher(reader);

    TopDocs search = searcher.search(new MatchAllDocsQuery(), filter, 1000);
    Assert.assertEquals(search.totalHits, 0);

    reader.close();
    writer.close();
}

From source file:org.openspaces.spatial.spi.LuceneSpatialConfiguration.java

License:Open Source License

protected StrategyFactory createStrategyFactory(LuceneSpatialQueryExtensionProvider provider) {
    String strategyString = provider.getCustomProperty(STRATEGY, STRATEGY_DEFAULT);
    SupportedSpatialStrategy spatialStrategy = SupportedSpatialStrategy.byName(strategyString);

    switch (spatialStrategy) {
    case RecursivePrefixTree: {
        final SpatialPrefixTree geohashPrefixTree = createSpatialPrefixTree(provider, _spatialContext);
        String distErrPctValue = provider.getCustomProperty(DIST_ERR_PCT, DIST_ERR_PCT_DEFAULT);
        final double distErrPct = Double.valueOf(distErrPctValue);

        return new StrategyFactory(spatialStrategy) {
            @Override//from w  w  w.  ja v  a  2 s. co m
            public SpatialStrategy createStrategy(String fieldName) {
                RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(geohashPrefixTree,
                        fieldName);
                strategy.setDistErrPct(distErrPct);
                return strategy;
            }
        };
    }
    case BBox: {
        return new StrategyFactory(spatialStrategy) {
            @Override
            public SpatialStrategy createStrategy(String fieldName) {
                return BBoxStrategy.newInstance(_spatialContext, fieldName);
            }
        };
    }
    case Composite: {
        final SpatialPrefixTree geohashPrefixTree = createSpatialPrefixTree(provider, _spatialContext);
        String distErrPctValue = provider.getCustomProperty(DIST_ERR_PCT, DIST_ERR_PCT_DEFAULT);
        final double distErrPct = Double.valueOf(distErrPctValue);

        return new StrategyFactory(spatialStrategy) {
            @Override
            public SpatialStrategy createStrategy(String fieldName) {
                RecursivePrefixTreeStrategy recursivePrefixTreeStrategy = new RecursivePrefixTreeStrategy(
                        geohashPrefixTree, fieldName);
                recursivePrefixTreeStrategy.setDistErrPct(distErrPct);
                SerializedDVStrategy serializedDVStrategy = new SerializedDVStrategy(_spatialContext,
                        fieldName);
                return new CompositeSpatialStrategy(fieldName, recursivePrefixTreeStrategy,
                        serializedDVStrategy);
            }
        };
    }
    default:
        throw new IllegalStateException("Unsupported strategy: " + spatialStrategy);
    }
}