From 8997b67b11f6ac9a467daf249c3f868aa38e7550 Mon Sep 17 00:00:00 2001 From: Likith B Date: Fri, 26 Jun 2026 11:30:37 +0530 Subject: [PATCH 01/10] MB-72376: Introducing New Geo-Shape Indexes --- segment.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/segment.go b/segment.go index 00b64a8..c5af237 100644 --- a/segment.go +++ b/segment.go @@ -273,3 +273,27 @@ type NestedSegment interface { // a parent document is deleted, all its nested child documents are also considered deleted. AddNestedDocuments(deleted *roaring.Bitmap) *roaring.Bitmap } + +type GeoCellSegment interface { + Segment + + GeoCellData(field string, except *roaring.Bitmap) (GeoCellData, error) +} + +type GeoCellData interface { + InnerCells() []uint64 + InnerDocIDs() []uint64 + + CrossCells() []uint64 + CrossDocIDs() []uint64 + + NumDocs() uint64 + DocNums() []uint64 + DocScores() []uint64 + + BoundingBox(docID uint64) ([]byte, error) + Shape(docID uint64) ([]byte, error) + + Exclude() *roaring.Bitmap + Close() +} From 31eb99216dd181991d96d2eeae453391cf2bc061 Mon Sep 17 00:00:00 2001 From: Likith B Date: Tue, 30 Jun 2026 19:21:12 +0530 Subject: [PATCH 02/10] code cleanup --- segment.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/segment.go b/segment.go index c5af237..6549a7f 100644 --- a/segment.go +++ b/segment.go @@ -274,26 +274,38 @@ type NestedSegment interface { AddNestedDocuments(deleted *roaring.Bitmap) *roaring.Bitmap } -type GeoCellSegment interface { +// GeoShapeV2Segment is an interface that extends the Segment interface +// to provide access to GeoShapeV2Data within the segment. +type GeoShapeV2Segment interface { Segment - GeoCellData(field string, except *roaring.Bitmap) (GeoCellData, error) + GeoShapeV2Data(field string, except *roaring.Bitmap) (GeoShapeV2Data, error) } -type GeoCellData interface { +// GeoShapeV2Data provides methods to access separate parts of the GeoShapeV2 data +// Internally, docID's are sequential from 0 to NumDocs()-1. A mapping of segment docID +// to the geo docID is stored and can be retrieved using the DocNums() method. +type GeoShapeV2Data interface { + // Returns all of the shapes' inner cells in sorted order InnerCells() []uint64 + // Returns the docIDs corresponding to the inner cells InnerDocIDs() []uint64 - + // Returns all of the shapes' cross cells in sorted order CrossCells() []uint64 + // Returns the docIDs corresponding to the cross cells CrossDocIDs() []uint64 - + // Returns the number of documents indexed NumDocs() uint64 + // Returns the segment's document numbers DocNums() []uint64 + // Returns the scores for the documents indexed DocScores() []uint64 - + // Returns the bounding box bytes for the corresponding internal document ID BoundingBox(docID uint64) ([]byte, error) + // Returns the shape bytes for the corresponding internal document ID Shape(docID uint64) ([]byte, error) - + // Returns the bitmap of documents that are excluded from the index Exclude() *roaring.Bitmap + // Closes the GeoShapeV2Data and releases any associated resources Close() } From a8a7240381c721b9688a6816f26fa6030b7c94a8 Mon Sep 17 00:00:00 2001 From: Likith B Date: Thu, 16 Jul 2026 18:09:21 +0530 Subject: [PATCH 03/10] added reuse of score arrays --- segment.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/segment.go b/segment.go index 6549a7f..f17e81b 100644 --- a/segment.go +++ b/segment.go @@ -306,6 +306,12 @@ type GeoShapeV2Data interface { Shape(docID uint64) ([]byte, error) // Returns the bitmap of documents that are excluded from the index Exclude() *roaring.Bitmap + // Returns a zeroed score array of length NumDocs() + // from a segment-level pool + GetScoreArray() []uint64 + // Returns the score array obtained via GetScoreArray back to the + // segment-level pool, the caller must not use them afterwards + PutScoreArray(scores []uint64) // Closes the GeoShapeV2Data and releases any associated resources Close() } From cda5f743753685e32cac4244f33586c125388585 Mon Sep 17 00:00:00 2001 From: Likith B Date: Fri, 17 Jul 2026 13:33:09 +0530 Subject: [PATCH 04/10] code cleanup --- segment.go | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/segment.go b/segment.go index f17e81b..c43b8ec 100644 --- a/segment.go +++ b/segment.go @@ -274,44 +274,48 @@ type NestedSegment interface { AddNestedDocuments(deleted *roaring.Bitmap) *roaring.Bitmap } -// GeoShapeV2Segment is an interface that extends the Segment interface +// GeoShapeV2Segment is an optional interface that a Segment may implement // to provide access to GeoShapeV2Data within the segment. type GeoShapeV2Segment interface { Segment + // GeoShapeV2Data returns the geo shape data for the given field, + // excluding any documents present in the except bitmap. GeoShapeV2Data(field string, except *roaring.Bitmap) (GeoShapeV2Data, error) } -// GeoShapeV2Data provides methods to access separate parts of the GeoShapeV2 data -// Internally, docID's are sequential from 0 to NumDocs()-1. A mapping of segment docID -// to the geo docID is stored and can be retrieved using the DocNums() method. +// GeoShapeV2Data provides methods to access separate parts of the GeoShapeV2 data. +// Internally, geo docIDs are sequential from 0 to NumDocs()-1; DocNums() maps each +// geo docID (the slice index) to its segment document number. type GeoShapeV2Data interface { - // Returns all of the shapes' inner cells in sorted order + // InnerCells returns all of the shapes' inner cells in ascending order. InnerCells() []uint64 - // Returns the docIDs corresponding to the inner cells + // InnerDocIDs returns the geo docIDs parallel to InnerCells(). InnerDocIDs() []uint64 - // Returns all of the shapes' cross cells in sorted order + // CrossCells returns all of the shapes' cross cells in ascending order. CrossCells() []uint64 - // Returns the docIDs corresponding to the cross cells + // CrossDocIDs returns the geo docIDs parallel to CrossCells(). CrossDocIDs() []uint64 - // Returns the number of documents indexed + // NumDocs returns the number of documents indexed. NumDocs() uint64 - // Returns the segment's document numbers + // DocNums returns the mapping from geo docID (the slice index) to + // segment document number. DocNums() []uint64 - // Returns the scores for the documents indexed + // DocScores returns the precomputed scores for the documents indexed, + // indexed by geo docID. DocScores() []uint64 - // Returns the bounding box bytes for the corresponding internal document ID - BoundingBox(docID uint64) ([]byte, error) - // Returns the shape bytes for the corresponding internal document ID - Shape(docID uint64) ([]byte, error) - // Returns the bitmap of documents that are excluded from the index - Exclude() *roaring.Bitmap - // Returns a zeroed score array of length NumDocs() - // from a segment-level pool + // BoundingBox returns the bounding box bytes for the given geo docID. + BoundingBox(geoDocID uint64) ([]byte, error) + // Shape returns the shape bytes for the given geo docID. + Shape(geoDocID uint64) ([]byte, error) + // Excluded returns the bitmap of documents that are excluded from the index. + Excluded() *roaring.Bitmap + // GetScoreArray returns a zeroed score array of length NumDocs() + // from a segment-level pool. GetScoreArray() []uint64 - // Returns the score array obtained via GetScoreArray back to the - // segment-level pool, the caller must not use them afterwards + // PutScoreArray returns the score array obtained via GetScoreArray back + // to the segment-level pool. The caller must not use it afterwards. PutScoreArray(scores []uint64) - // Closes the GeoShapeV2Data and releases any associated resources + // Close closes the GeoShapeV2Data and releases any associated resources. Close() } From 191bdd72e200cb184daed725f1c40aaa3490d7f0 Mon Sep 17 00:00:00 2001 From: Likith B Date: Mon, 20 Jul 2026 19:52:06 +0530 Subject: [PATCH 05/10] bug fix --- segment.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/segment.go b/segment.go index c43b8ec..c7aaa40 100644 --- a/segment.go +++ b/segment.go @@ -301,9 +301,10 @@ type GeoShapeV2Data interface { // DocNums returns the mapping from geo docID (the slice index) to // segment document number. DocNums() []uint64 - // DocScores returns the precomputed scores for the documents indexed, - // indexed by geo docID. - DocScores() []uint64 + // DocScores returns the precomputed inner and cross cell scores (in + // that order) for the documents indexed, each indexed by geo docID. + // These mirror index.GeoShapeV2Field.Scores() for every doc in the segment. + DocScores() (innerScores, crossScores []uint64) // BoundingBox returns the bounding box bytes for the given geo docID. BoundingBox(geoDocID uint64) ([]byte, error) // Shape returns the shape bytes for the given geo docID. From 3a07d5e030e2c43071b8d14eab72397e75d71cd6 Mon Sep 17 00:00:00 2001 From: Likith B Date: Wed, 22 Jul 2026 11:16:51 +0530 Subject: [PATCH 06/10] code cleanup --- segment.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/segment.go b/segment.go index c7aaa40..c6faa9c 100644 --- a/segment.go +++ b/segment.go @@ -303,19 +303,19 @@ type GeoShapeV2Data interface { DocNums() []uint64 // DocScores returns the precomputed inner and cross cell scores (in // that order) for the documents indexed, each indexed by geo docID. - // These mirror index.GeoShapeV2Field.Scores() for every doc in the segment. DocScores() (innerScores, crossScores []uint64) // BoundingBox returns the bounding box bytes for the given geo docID. BoundingBox(geoDocID uint64) ([]byte, error) // Shape returns the shape bytes for the given geo docID. Shape(geoDocID uint64) ([]byte, error) - // Excluded returns the bitmap of documents that are excluded from the index. + // Excluded returns the bitmap of geo document IDs that are excluded + // from the index. Excluded() *roaring.Bitmap // GetScoreArray returns a zeroed score array of length NumDocs() // from a segment-level pool. GetScoreArray() []uint64 // PutScoreArray returns the score array obtained via GetScoreArray back - // to the segment-level pool. The caller must not use it afterwards. + // to the segment-level pool. PutScoreArray(scores []uint64) // Close closes the GeoShapeV2Data and releases any associated resources. Close() From c2e9050fe4a381063915e6c511568d9815b17dba Mon Sep 17 00:00:00 2001 From: Likith B Date: Wed, 22 Jul 2026 15:49:20 +0530 Subject: [PATCH 07/10] indexing optimizations --- segment.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/segment.go b/segment.go index c6faa9c..557d8d0 100644 --- a/segment.go +++ b/segment.go @@ -291,16 +291,16 @@ type GeoShapeV2Data interface { // InnerCells returns all of the shapes' inner cells in ascending order. InnerCells() []uint64 // InnerDocIDs returns the geo docIDs parallel to InnerCells(). - InnerDocIDs() []uint64 + InnerDocIDs() []uint32 // CrossCells returns all of the shapes' cross cells in ascending order. CrossCells() []uint64 // CrossDocIDs returns the geo docIDs parallel to CrossCells(). - CrossDocIDs() []uint64 + CrossDocIDs() []uint32 // NumDocs returns the number of documents indexed. NumDocs() uint64 // DocNums returns the mapping from geo docID (the slice index) to // segment document number. - DocNums() []uint64 + DocNums() []uint32 // DocScores returns the precomputed inner and cross cell scores (in // that order) for the documents indexed, each indexed by geo docID. DocScores() (innerScores, crossScores []uint64) From fa10df50474b305cbc8bce404fd403e3f926a858 Mon Sep 17 00:00:00 2001 From: Likith B Date: Mon, 27 Jul 2026 18:53:07 +0530 Subject: [PATCH 08/10] using score maps instead of slices --- segment.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/segment.go b/segment.go index 557d8d0..b84c240 100644 --- a/segment.go +++ b/segment.go @@ -311,12 +311,12 @@ type GeoShapeV2Data interface { // Excluded returns the bitmap of geo document IDs that are excluded // from the index. Excluded() *roaring.Bitmap - // GetScoreArray returns a zeroed score array of length NumDocs() - // from a segment-level pool. - GetScoreArray() []uint64 - // PutScoreArray returns the score array obtained via GetScoreArray back - // to the segment-level pool. - PutScoreArray(scores []uint64) + // GetScoreArray returns an empty score map, keyed by geo docID, from a + // segment-level pool. + GetScoreArray() map[uint32]uint64 + // PutScoreArray clears the score map obtained via GetScoreArray and + // returns it to the segment-level pool. + PutScoreArray(scores map[uint32]uint64) // Close closes the GeoShapeV2Data and releases any associated resources. Close() } From 591a6229ffd538de4106580c81a08dd1ae303ed9 Mon Sep 17 00:00:00 2001 From: Likith B Date: Tue, 28 Jul 2026 15:38:42 +0530 Subject: [PATCH 09/10] var rename --- segment.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/segment.go b/segment.go index b84c240..8279043 100644 --- a/segment.go +++ b/segment.go @@ -311,12 +311,12 @@ type GeoShapeV2Data interface { // Excluded returns the bitmap of geo document IDs that are excluded // from the index. Excluded() *roaring.Bitmap - // GetScoreArray returns an empty score map, keyed by geo docID, from a + // GetScoreMap returns an empty score map, keyed by geo docID, from a // segment-level pool. - GetScoreArray() map[uint32]uint64 - // PutScoreArray clears the score map obtained via GetScoreArray and + GetScoreMap() map[uint32]uint64 + // PutScoreMap clears the score map obtained via GetScoreMap and // returns it to the segment-level pool. - PutScoreArray(scores map[uint32]uint64) + PutScoreMap(scores map[uint32]uint64) // Close closes the GeoShapeV2Data and releases any associated resources. Close() } From 3ebb20f85c63d1a8c5b19edd4debacf6414ec6bd Mon Sep 17 00:00:00 2001 From: Likith B Date: Wed, 29 Jul 2026 11:45:51 +0530 Subject: [PATCH 10/10] addressing reviews --- go.mod | 2 +- go.sum | 4 ++-- segment.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 77539d0..bbaa942 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.24.0 require ( github.com/RoaringBitmap/roaring/v2 v2.14.5 - github.com/blevesearch/bleve_index_api v1.4.0 + github.com/blevesearch/bleve_index_api v1.4.1-0.20260729060817-8e56340f2a7e ) require ( diff --git a/go.sum b/go.sum index 5fe34fc..217b0d8 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/RoaringBitmap/roaring/v2 v2.14.5 h1:ckd0o545JqDPeVJDgeFoaM21eBixUnlWf github.com/RoaringBitmap/roaring/v2 v2.14.5/go.mod h1:eq4wdNXxtJIS/oikeCzdX1rBzek7ANzbth041hrU8Q4= github.com/bits-and-blooms/bitset v1.24.2 h1:M7/NzVbsytmtfHbumG+K2bremQPMJuqv1JD3vOaFxp0= github.com/bits-and-blooms/bitset v1.24.2/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= -github.com/blevesearch/bleve_index_api v1.4.0 h1:xoCC4dvTizjcsZu7yO9Ua+/259K09BrirjTwLkx2MpY= -github.com/blevesearch/bleve_index_api v1.4.0/go.mod h1:xvd48t5XMeeioWQ5/jZvgLrV98flT2rdvEJ3l/ki4Ko= +github.com/blevesearch/bleve_index_api v1.4.1-0.20260729060817-8e56340f2a7e h1:WJ3JnFiBuZ0m1mXaniDHpbZxKU8hjp7SIhqHopSnaM4= +github.com/blevesearch/bleve_index_api v1.4.1-0.20260729060817-8e56340f2a7e/go.mod h1:xvd48t5XMeeioWQ5/jZvgLrV98flT2rdvEJ3l/ki4Ko= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM= diff --git a/segment.go b/segment.go index 8279043..49d1d8b 100644 --- a/segment.go +++ b/segment.go @@ -305,9 +305,9 @@ type GeoShapeV2Data interface { // that order) for the documents indexed, each indexed by geo docID. DocScores() (innerScores, crossScores []uint64) // BoundingBox returns the bounding box bytes for the given geo docID. - BoundingBox(geoDocID uint64) ([]byte, error) + BoundingBox(geoDocID uint32) ([]byte, error) // Shape returns the shape bytes for the given geo docID. - Shape(geoDocID uint64) ([]byte, error) + Shape(geoDocID uint32) ([]byte, error) // Excluded returns the bitmap of geo document IDs that are excluded // from the index. Excluded() *roaring.Bitmap