Search in sources :

Example 1 with QuadPrefixTree

use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree 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 2 with QuadPrefixTree

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

the class RandomSpatialOpFuzzyPrefixTreeTest method setupQuadGrid.

private void setupQuadGrid(int maxLevels, boolean packedQuadPrefixTree) {
    //non-geospatial makes this test a little easier (in gridSnap), and using boundary values 2^X raises
    // the prospect of edge conditions we want to test, plus makes for simpler numbers (no decimals).
    SpatialContextFactory factory = new SpatialContextFactory();
    factory.geo = false;
    factory.worldBounds = new RectangleImpl(0, 256, -128, 128, null);
    this.ctx = factory.newSpatialContext();
    //A fairly shallow grid, and default 2.5% distErrPct
    if (maxLevels == -1)
        //max 64k cells (4^8), also 256*256
        maxLevels = randomIntBetween(1, 8);
    if (packedQuadPrefixTree) {
        this.grid = new PackedQuadPrefixTree(ctx, maxLevels);
    } else {
        this.grid = new QuadPrefixTree(ctx, maxLevels);
    }
    this.strategy = newRPT();
}
Also used : SpatialContextFactory(org.locationtech.spatial4j.context.SpatialContextFactory) PackedQuadPrefixTree(org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) RectangleImpl(org.locationtech.spatial4j.shape.impl.RectangleImpl) PackedQuadPrefixTree(org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree)

Example 3 with QuadPrefixTree

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

the class HeatmapFacetCounterTest method testQueryCircle.

@Test
public void testQueryCircle() throws IOException {
    //overwrite setUp; non-geo bounds is more straight-forward; otherwise 88,88 would actually be practically north,
    final SpatialContextFactory spatialContextFactory = new SpatialContextFactory();
    spatialContextFactory.geo = false;
    spatialContextFactory.worldBounds = new RectangleImpl(-90, 90, -90, 90, null);
    ctx = spatialContextFactory.newSpatialContext();
    final int LEVEL = 4;
    grid = new QuadPrefixTree(ctx, LEVEL);
    strategy = new RecursivePrefixTreeStrategy(grid, getTestClass().getSimpleName());
    Circle circle = ctx.makeCircle(0, 0, 89);
    //top-right, inside bbox of circle but not the circle
    adoc("0", ctx.makePoint(88, 88));
    //clearly inside; dead center in fact
    adoc("1", ctx.makePoint(0, 0));
    commit();
    final HeatmapFacetCounter.Heatmap heatmap = HeatmapFacetCounter.calcFacets((PrefixTreeStrategy) strategy, indexSearcher.getTopReaderContext(), null, circle, LEVEL, 1000);
    //assert that only one point is found, not 2
    boolean foundOne = false;
    for (int count : heatmap.counts) {
        switch(count) {
            case 0:
                break;
            case 1:
                //this is the first
                assertFalse(foundOne);
                foundOne = true;
                break;
            default:
                fail("counts should be 0 or 1: " + count);
        }
    }
    assertTrue(foundOne);
}
Also used : Circle(org.locationtech.spatial4j.shape.Circle) SpatialContextFactory(org.locationtech.spatial4j.context.SpatialContextFactory) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) RectangleImpl(org.locationtech.spatial4j.shape.impl.RectangleImpl) Point(org.locationtech.spatial4j.shape.Point) Test(org.junit.Test)

Example 4 with QuadPrefixTree

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

the class JtsPolygonTest method testBadPrefixTreePrune.

/**
   * 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.makePoint(-122.88, 48.54);
    Point lowerright = ctx.makePoint(-122.82, 48.62);
    Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, ctx.makeRectangle(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);
}
Also used : SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) Shape(org.locationtech.spatial4j.shape.Shape) Query(org.apache.lucene.search.Query) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) Point(org.locationtech.spatial4j.shape.Point) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc) TopDocs(org.apache.lucene.search.TopDocs) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) TextField(org.apache.lucene.document.TextField) Test(org.junit.Test)

Example 5 with QuadPrefixTree

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

the class TestTermQueryPrefixGridStrategy method testNGramPrefixGridLosAngeles.

@Test
public void testNGramPrefixGridLosAngeles() throws IOException {
    SpatialContext ctx = SpatialContext.GEO;
    TermQueryPrefixTreeStrategy prefixGridStrategy = new TermQueryPrefixTreeStrategy(new QuadPrefixTree(ctx), "geo");
    Shape point = ctx.makePoint(-118.243680, 34.052230);
    Document losAngeles = new Document();
    losAngeles.add(new StringField("name", "Los Angeles", Field.Store.YES));
    for (Field field : prefixGridStrategy.createIndexableFields(point)) {
        losAngeles.add(field);
    }
    //just for diagnostics
    losAngeles.add(new StoredField(prefixGridStrategy.getFieldName(), point.toString()));
    addDocumentsAndCommit(Arrays.asList(losAngeles));
    // This won't work with simple spatial context...
    SpatialArgsParser spatialArgsParser = new SpatialArgsParser();
// TODO... use a non polygon query
//    SpatialArgs spatialArgs = spatialArgsParser.parse(
//        "Intersects(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",
//        new SimpleSpatialContext());
//    Query query = prefixGridStrategy.makeQuery(spatialArgs, fieldInfo);
//    SearchResults searchResults = executeQuery(query, 1);
//    assertEquals(1, searchResults.numFound);
}
Also used : Field(org.apache.lucene.document.Field) StringField(org.apache.lucene.document.StringField) StoredField(org.apache.lucene.document.StoredField) StoredField(org.apache.lucene.document.StoredField) SpatialContext(org.locationtech.spatial4j.context.SpatialContext) Shape(org.locationtech.spatial4j.shape.Shape) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) SpatialArgsParser(org.apache.lucene.spatial.query.SpatialArgsParser) StringField(org.apache.lucene.document.StringField) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Aggregations

QuadPrefixTree (org.apache.lucene.spatial.prefix.tree.QuadPrefixTree)11 Test (org.junit.Test)5 GeohashPrefixTree (org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)4 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)4 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)4 ArrayList (java.util.ArrayList)3 RecursivePrefixTreeStrategy (org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy)3 TermQueryPrefixTreeStrategy (org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy)3 SpatialContextFactory (org.locationtech.spatial4j.context.SpatialContextFactory)3 RectangleImpl (org.locationtech.spatial4j.shape.impl.RectangleImpl)3 ParametersFactory (com.carrotsearch.randomizedtesting.annotations.ParametersFactory)2 Document (org.apache.lucene.document.Document)2 Field (org.apache.lucene.document.Field)2 PackedQuadPrefixTree (org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree)2 SerializedDVStrategy (org.apache.lucene.spatial.serialized.SerializedDVStrategy)2 Point (org.locationtech.spatial4j.shape.Point)2 Shape (org.locationtech.spatial4j.shape.Shape)2 StoredField (org.apache.lucene.document.StoredField)1 StringField (org.apache.lucene.document.StringField)1 TextField (org.apache.lucene.document.TextField)1