Skip to content

Commit 15ca534

Browse files
committed
added reuse of score arrays and different api for query cells
1 parent 2a9221f commit 15ca534

5 files changed

Lines changed: 43 additions & 10 deletions

File tree

geo/geo_s2plugin_impl.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ func (p *Point) Cells() ([]uint64, []uint64) {
251251
return nil, nil
252252
}
253253

254+
func (p *Point) QueryCells() ([]uint64, []uint64) {
255+
// placeholder implementation
256+
return nil, nil
257+
}
258+
254259
func (p *Point) BoundingBox() index.GeoJSON {
255260
// placeholder implementation
256261
return nil
@@ -308,6 +313,11 @@ func (br *boundedRectangle) Cells() ([]uint64, []uint64) {
308313
return nil, nil
309314
}
310315

316+
func (br *boundedRectangle) QueryCells() ([]uint64, []uint64) {
317+
// placeholder implementation
318+
return nil, nil
319+
}
320+
311321
func (br *boundedRectangle) BoundingBox() index.GeoJSON {
312322
// placeholder implementation
313323
return nil
@@ -366,6 +376,11 @@ func (bp *boundedPolygon) Cells() ([]uint64, []uint64) {
366376
return nil, nil
367377
}
368378

379+
func (bp *boundedPolygon) QueryCells() ([]uint64, []uint64) {
380+
// placeholder implementation
381+
return nil, nil
382+
}
383+
369384
func (bp *boundedPolygon) BoundingBox() index.GeoJSON {
370385
// placeholder implementation
371386
return nil
@@ -424,6 +439,11 @@ func (pd *pointDistance) Cells() ([]uint64, []uint64) {
424439
return nil, nil
425440
}
426441

442+
func (pd *pointDistance) QueryCells() ([]uint64, []uint64) {
443+
// placeholder implementation
444+
return nil, nil
445+
}
446+
427447
func (pd *pointDistance) BoundingBox() index.GeoJSON {
428448
// placeholder implementation
429449
return nil

geov2/query_contains.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type containsQuery struct {
3434
}
3535

3636
func NewContainsQuery(shape index.GeoJSON) Query {
37-
inner, cross := shape.Cells()
37+
inner, cross := shape.QueryCells()
3838

3939
score := CalcCellsScore(inner) + CalcCellsScore(cross)
4040

@@ -56,8 +56,12 @@ func (cq *containsQuery) Evaluate(geoData segment.GeoShapeV2Data) *util.Bitset {
5656
hits := util.NewBitset(numDocs, exclude)
5757
maybeHits := util.NewBitset(numDocs, exclude)
5858

59-
innerScores := make([]uint64, numDocs)
60-
crossScores := make([]uint64, numDocs)
59+
// obtain zeroed score arrays from the segment-level pool and return
60+
// them once the evaluation is done
61+
innerScores := geoData.GetScoreArray()
62+
crossScores := geoData.GetScoreArray()
63+
defer geoData.PutScoreArray(innerScores)
64+
defer geoData.PutScoreArray(crossScores)
6165

6266
// create an evaluator instance to scan the query cells against the index cells
6367
evaluator := NewQueryEvaluator(cq, geoData)

geov2/query_disjoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type disjointQuery struct {
2929
}
3030

3131
func NewDisjointQuery(shape index.GeoJSON) Query {
32-
inner, cross := shape.Cells()
32+
inner, cross := shape.QueryCells()
3333

3434
return &disjointQuery{
3535
innerCells: inner,

geov2/query_intersects.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type intersectsQuery struct {
3232
}
3333

3434
func NewIntersectsQuery(shape index.GeoJSON) Query {
35-
inner, cross := shape.Cells()
35+
inner, cross := shape.QueryCells()
3636

3737
return &intersectsQuery{
3838
innerCells: inner,
@@ -51,8 +51,12 @@ func (iq *intersectsQuery) Evaluate(geoData segment.GeoShapeV2Data) *util.Bitset
5151
hits := util.NewBitset(numDocs, exclude)
5252
maybeHits := util.NewBitset(numDocs, exclude)
5353

54-
innerScores := make([]uint64, numDocs)
55-
crossScores := make([]uint64, numDocs)
54+
// obtain zeroed score arrays from the segment-level pool and return
55+
// them once the evaluation is done
56+
innerScores := geoData.GetScoreArray()
57+
crossScores := geoData.GetScoreArray()
58+
defer geoData.PutScoreArray(innerScores)
59+
defer geoData.PutScoreArray(crossScores)
5660

5761
// create an evaluator instance to scan the query cells against the index cells
5862
evaluator := NewQueryEvaluator(iq, geoData)

geov2/query_within.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type withinQuery struct {
3232
}
3333

3434
func NewWithinQuery(shape index.GeoJSON) Query {
35-
inner, cross := shape.Cells()
35+
inner, cross := shape.QueryCells()
3636

3737
return &withinQuery{
3838
innerCells: inner,
@@ -51,8 +51,13 @@ func (wq *withinQuery) Evaluate(geoData segment.GeoShapeV2Data) *util.Bitset {
5151
hits := util.NewBitset(numDocs, exclude)
5252
maybeHits := util.NewBitset(numDocs, exclude)
5353

54-
innerScores := make([]uint64, numDocs)
55-
crossScores := make([]uint64, numDocs)
54+
// obtain zeroed score arrays from the segment-level pool and return
55+
// them once the evaluation is done
56+
innerScores := geoData.GetScoreArray()
57+
crossScores := geoData.GetScoreArray()
58+
defer geoData.PutScoreArray(innerScores)
59+
defer geoData.PutScoreArray(crossScores)
60+
5661
docScores := geoData.DocScores()
5762

5863
// create an evaluator instance to scan the query cells against the index cells

0 commit comments

Comments
 (0)