From 68c4fb091f7fe520f408c70c01ec6d9c0b59025d Mon Sep 17 00:00:00 2001 From: Likith B Date: Fri, 26 Jun 2026 11:30:37 +0530 Subject: [PATCH 1/7] 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 fb338ba15561e8303e594c7a88c8109509d3216e Mon Sep 17 00:00:00 2001 From: Likith B Date: Tue, 30 Jun 2026 19:21:12 +0530 Subject: [PATCH 2/7] 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 4ed1d5288be9df4ce00bc3569635e9f3ca52e579 Mon Sep 17 00:00:00 2001 From: Likith B Date: Thu, 16 Jul 2026 18:09:21 +0530 Subject: [PATCH 3/7] 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 86a598bf5fef1da48d9d1ca4127a4ac185d52d90 Mon Sep 17 00:00:00 2001 From: Likith B Date: Fri, 17 Jul 2026 13:33:09 +0530 Subject: [PATCH 4/7] 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 14364bb392980dd58a7c3204cfdd16f40641598c Mon Sep 17 00:00:00 2001 From: Likith B Date: Mon, 20 Jul 2026 19:52:06 +0530 Subject: [PATCH 5/7] 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 a04faa1eca93320e738cfc9a29de589b907ae67e Mon Sep 17 00:00:00 2001 From: Likith B Date: Wed, 22 Jul 2026 11:16:51 +0530 Subject: [PATCH 6/7] 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 d4b74c375567849f04843870a934866209bf7a44 Mon Sep 17 00:00:00 2001 From: Likith B Date: Wed, 22 Jul 2026 15:49:20 +0530 Subject: [PATCH 7/7] 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)