Search in sources :

Example 6 with SpatialArgs

use of org.apache.lucene.spatial.query.SpatialArgs in project lucene-solr by apache.

the class TestPointVectorStrategy method testCircleShapeSupport.

@Test
public void testCircleShapeSupport() {
    this.strategy = PointVectorStrategy.newInstance(ctx, getClass().getSimpleName());
    Circle circle = ctx.makeCircle(ctx.makePoint(0, 0), 10);
    SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);
    Query query = this.strategy.makeQuery(args);
    assertNotNull(query);
}
Also used : Circle(org.locationtech.spatial4j.shape.Circle) SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Test(org.junit.Test)

Example 7 with SpatialArgs

use of org.apache.lucene.spatial.query.SpatialArgs 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 8 with SpatialArgs

use of org.apache.lucene.spatial.query.SpatialArgs in project lucene-solr by apache.

the class JtsPolygonTest method testCloseButNoMatch.

@Test
public /** LUCENE-4464 */
void testCloseButNoMatch() throws Exception {
    getAddAndVerifyIndexedDocuments("LUCENE-4464.txt");
    SpatialArgs args = q("POLYGON((-93.18100824442227 45.25676372469945," + "-93.23182001200654 45.21421290799412," + "-93.16315546122038 45.23742639412364," + "-93.18100824442227 45.25676372469945))", LUCENE_4464_distErrPct);
    SearchResults got = executeQuery(strategy.makeQuery(args), 100);
    assertEquals(1, got.numFound);
    assertEquals("poly2", got.results.get(0).document.get("id"));
//did not find poly 1 !
}
Also used : SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) Test(org.junit.Test)

Example 9 with SpatialArgs

use of org.apache.lucene.spatial.query.SpatialArgs in project lucene-solr by apache.

the class SpatialPrefixTreeTest method testBadPrefixTreePrune.

/**
   * A PrefixTree pruning optimization gone bad, applicable when optimize=true.
   * See <a href="https://issues.apache.org/jira/browse/LUCENE-4770">LUCENE-4770</a>.
   */
@Test
public void testBadPrefixTreePrune() throws Exception {
    trie = new QuadPrefixTree(ctx, 12);
    TermQueryPrefixTreeStrategy strategy = new TermQueryPrefixTreeStrategy(trie, "geo");
    Document doc = new Document();
    doc.add(new TextField("id", "1", Store.YES));
    Shape area = ctx.makeRectangle(-122.82, -122.78, 48.54, 48.56);
    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) 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) TextField(org.apache.lucene.document.TextField) TermQueryPrefixTreeStrategy(org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy) Test(org.junit.Test)

Example 10 with SpatialArgs

use of org.apache.lucene.spatial.query.SpatialArgs in project lucene-solr by apache.

the class TestPointVectorStrategy method testInvalidQueryShape.

@Test(expected = UnsupportedOperationException.class)
public void testInvalidQueryShape() {
    this.strategy = PointVectorStrategy.newInstance(ctx, getClass().getSimpleName());
    Point point = ctx.makePoint(0, 0);
    SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, point);
    this.strategy.makeQuery(args);
}
Also used : SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) Point(org.locationtech.spatial4j.shape.Point) Test(org.junit.Test)

Aggregations

SpatialArgs (org.apache.lucene.spatial.query.SpatialArgs)34 Query (org.apache.lucene.search.Query)16 Shape (org.locationtech.spatial4j.shape.Shape)14 Test (org.junit.Test)12 Point (org.locationtech.spatial4j.shape.Point)10 SpatialOperation (org.apache.lucene.spatial.query.SpatialOperation)6 Document (org.apache.lucene.document.Document)5 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)5 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 TopDocs (org.apache.lucene.search.TopDocs)4 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)3 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 Field (org.apache.lucene.document.Field)2 TextField (org.apache.lucene.document.TextField)2 IndexReader (org.apache.lucene.index.IndexReader)2 Term (org.apache.lucene.index.Term)2 BooleanFilter (org.apache.lucene.queries.BooleanFilter)2