lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [25/50] [abbrv] lucene-solr:jira/solr-12509: isolate large vertex shape test from basic shape test
Date Thu, 19 Jul 2018 08:41:26 GMT
isolate large vertex shape test from basic shape test


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/f291f3eb
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/f291f3eb
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/f291f3eb

Branch: refs/heads/jira/solr-12509
Commit: f291f3eb6c91f7288226c48d72bc41a9c377e867
Parents: d387cb5
Author: Nicholas Knize <nknize@gmail.com>
Authored: Sun Jul 15 15:57:40 2018 -0500
Committer: Nicholas Knize <nknize@gmail.com>
Committed: Sun Jul 15 16:12:06 2018 -0500

----------------------------------------------------------------------
 .../apache/lucene/document/TestLatLonShape.java | 55 ++++++++++++++++----
 1 file changed, 45 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f291f3eb/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.java
index e1cda5e..d0a4b32 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.java
@@ -28,6 +28,7 @@ import org.apache.lucene.index.SerialMergeScheduler;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.TestUtil;
 import org.junit.Ignore;
@@ -74,8 +75,48 @@ public class TestLatLonShape extends LuceneTestCase {
     dir.close();
   }
 
-  /** test we can search for a point */
+  /** test we can search for a point with a standard number of vertices*/
   public void testBasicIntersects() throws Exception {
+    int numVertices = TestUtil.nextInt(random(), 50, 100);
+    Directory dir = newDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
+
+    // add a random polygon without a hole
+    Polygon p = GeoTestUtil.createRegularPolygon(0, 90, atLeast(1000000), numVertices);
+    Document document = new Document();
+    addPolygonsToDoc(FIELDNAME, document, p);
+    writer.addDocument(document);
+
+    // add a random polygon with a hole
+    Polygon inner = new Polygon(new double[] {-1d, -1d, 1d, 1d, -1d},
+        new double[] {-91d, -89d, -89d, -91.0, -91.0});
+    Polygon outer = GeoTestUtil.createRegularPolygon(0, -90, atLeast(1000000), numVertices);
+
+    document = new Document();
+    addPolygonsToDoc(FIELDNAME, document, new Polygon(outer.getPolyLats(), outer.getPolyLons(),
inner));
+    writer.addDocument(document);
+
+    ////// search /////
+    // search an intersecting bbox
+    IndexReader reader = writer.getReader();
+    writer.close();
+    IndexSearcher searcher = newSearcher(reader);
+    Query q = newRectQuery(FIELDNAME, -1d, 1d, p.minLon, p.maxLon);
+    assertEquals(1, searcher.count(q));
+
+    // search a disjoint bbox
+    q = newRectQuery(FIELDNAME, p.minLat-1d, p.minLat+1, p.minLon-1d, p.minLon+1d);
+    assertEquals(0, searcher.count(q));
+
+    // search a bbox in the hole
+    q = newRectQuery(FIELDNAME, inner.minLat + 1e-6, inner.maxLat - 1e-6, inner.minLon +
1e-6, inner.maxLon - 1e-6);
+    assertEquals(0, searcher.count(q));
+
+    IOUtils.close(reader, dir);
+  }
+
+  /** test we can search for a point with a large number of vertices*/
+  public void testLargeVertexPolygon() throws Exception {
     int numVertices = TestUtil.nextInt(random(), 200000, 500000);
     IndexWriterConfig iwc = newIndexWriterConfig();
     iwc.setMergeScheduler(new SerialMergeScheduler());
@@ -83,12 +124,7 @@ public class TestLatLonShape extends LuceneTestCase {
     if (mbd != -1 && mbd < numVertices/100) {
       iwc.setMaxBufferedDocs(numVertices/100);
     }
-    Directory dir;
-    if (numVertices > 300000) {
-      dir = newFSDirectory(createTempDir(getClass().getSimpleName()));
-    } else {
-      dir = newDirectory();
-    }
+    Directory dir = newFSDirectory(createTempDir(getClass().getSimpleName()));
     IndexWriter writer = new IndexWriter(dir, iwc);
 
     // add a random polygon without a hole
@@ -109,6 +145,7 @@ public class TestLatLonShape extends LuceneTestCase {
     ////// search /////
     // search an intersecting bbox
     IndexReader reader = DirectoryReader.open(writer);
+    writer.close();
     IndexSearcher searcher = newSearcher(reader);
     Query q = newRectQuery(FIELDNAME, -1d, 1d, p.minLon, p.maxLon);
     assertEquals(1, searcher.count(q));
@@ -121,8 +158,6 @@ public class TestLatLonShape extends LuceneTestCase {
     q = newRectQuery(FIELDNAME, inner.minLat + 1e-6, inner.maxLat - 1e-6, inner.minLon +
1e-6, inner.maxLon - 1e-6);
     assertEquals(0, searcher.count(q));
 
-    reader.close();
-    writer.close();
-    dir.close();
+    IOUtils.close(reader, dir);
   }
 }


Mime
View raw message