Repository: blevesearch/bleve
Pull request #1674 (2022-04-20 10:30:41)

Updating the s2/geo version
This version bump primarily includes a porting fix
in s2/loop.go in the original golang port version.

This change also includes a unit test that covers
the case.


Patch:
diff --git a/go.mod b/go.mod
index 2bbe0222..4750a341 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
 	github.com/RoaringBitmap/roaring v0.9.4
 	github.com/bits-and-blooms/bitset v1.2.0
 	github.com/blevesearch/bleve_index_api v1.0.2-0.20220328092731-fdf526452081
-	github.com/blevesearch/geo v0.1.9
+	github.com/blevesearch/geo v0.1.10
 	github.com/blevesearch/go-metrics v0.0.0-20201227073835-cf1acfcdf475
 	github.com/blevesearch/go-porterstemmer v1.0.3
 	github.com/blevesearch/goleveldb v1.0.1
diff --git a/go.sum b/go.sum
index ac2f2bd5..c0460cfe 100644
--- a/go.sum
+++ b/go.sum
@@ -9,6 +9,8 @@ github.com/blevesearch/bleve_index_api v1.0.2-0.20220328092731-fdf526452081 h1:f
 github.com/blevesearch/bleve_index_api v1.0.2-0.20220328092731-fdf526452081/go.mod h1:fiwKS0xLEm+gBRgv5mumf0dhgFr2mDgZah1pqv1c1M4=
 github.com/blevesearch/geo v0.1.9 h1:3PkWcg/Os+AVezVKptfHVv6HbIL0qZ9hodQTnoBnLn8=
 github.com/blevesearch/geo v0.1.9/go.mod h1:XqONL2MSA0A3hDWq35mX+dkXbJwq+LNdSgDHvqOhQZM=
+github.com/blevesearch/geo v0.1.10 h1:KgUEYKPPz8uwzIIpUpotWiBAVCqI+xAM8qWad0UKIf0=
+github.com/blevesearch/geo v0.1.10/go.mod h1:XqONL2MSA0A3hDWq35mX+dkXbJwq+LNdSgDHvqOhQZM=
 github.com/blevesearch/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:kDy+zgJFJJoJYBvdfBSiZYBbdsUL0XcjHYWezpQBGPA=
 github.com/blevesearch/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:9eJDeqxJ3E7WnLebQUlPD7ZjSce7AnDb9vjGmMCbD0A=
 github.com/blevesearch/go-porterstemmer v1.0.3 h1:GtmsqID0aZdCSNiY8SkuPJ12pD4jI+DdXTAn4YRcHCo=


Test patch:
diff --git a/search/searcher/search_geoshape_polygon_test.go b/search/searcher/search_geoshape_polygon_test.go
index 2b24d3c9..5672d4f7 100644
--- a/search/searcher/search_geoshape_polygon_test.go
+++ b/search/searcher/search_geoshape_polygon_test.go
@@ -680,3 +680,77 @@ func setupGeoJsonShapesIndexForMultiPolygonQuery(t *testing.T) index.Index {
 
 	return i
 }
+
+func setupGeoJsonPolygonS2LoopPortingIssue(t *testing.T) index.Index {
+	analysisQueue := index.NewAnalysisQueue(1)
+	i, err := scorch.NewScorch(
+		gtreap.Name,
+		map[string]interface{}{
+			"path":          "",
+			"spatialPlugin": "s2",
+		},
+		analysisQueue)
+	if err != nil {
+		t.Fatal(err)
+	}
+	err = i.Open()
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	polygon1 := [][][][]float64{{{{-135.0, -38.0},
+		{149.0, -38.0}, {149.0, 77.0},
+		{-135.0, 77.0}}}}
+	doc := document.NewDocument("polygon1")
+	doc.AddField(document.NewGeoShapeFieldWithIndexingOptions("geometry", []uint64{},
+		polygon1, "polygon", document.DefaultGeoShapeIndexingOptions))
+	err = i.Update(doc)
+	if err != nil {
+		t.Fatal(err)
+	}
+	return i
+}
+
+func TestGeoJsonPolygonContainsQueryS2LoopPortingIssue(t *testing.T) {
+	tests := []struct {
+		polygon [][][]float64
+		field   string
+		want    []string
+	}{
+
+		// test containment query polygon for polygon1.
+		{[][][]float64{{{13.007812500000002, 37.99616267972809},
+			{13.559375000000002, 37.99616267972809}, {13.559375000000002, 38.472819658516866},
+			{13.007812500000002, 38.472819658516866}}},
+			"geometry", []string{"polygon1"}},
+
+		// test containment query polygon for polygon1.
+		{[][][]float64{{{13.007812500000002, 37.99616267972809},
+			{13.359375000000002, 37.99616267972809}, {13.359375000000002, 38.272819658516866},
+			{13.007812500000002, 38.272819658516866}}},
+			"geometry", []string{"polygon1"}},
+	}
+	i := setupGeoJsonPolygonS2LoopPortingIssue(t)
+	indexReader, err := i.Reader()
+	if err != nil {
+		t.Error(err)
+	}
+	defer func() {
+		err = indexReader.Close()
+		if err != nil {
+			t.Fatal(err)
+		}
+	}()
+
+	for n, test := range tests {
+		got, err := runGeoShapePolygonQueryWithRelation("contains",
+			indexReader, test.polygon, test.field)
+		if err != nil {
+			t.Fatal(err)
+		}
+		if !reflect.DeepEqual(got, test.want) {
+			t.Errorf("test %d, expected %v, got %v for polygon: %+v",
+				n, test.want, got, test.polygon)
+		}
+	}
+}