Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: repeat compute in case one field aggregation multiple #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Marty Schoch <[email protected]>
Michael Schuett <[email protected]>
Akshay Shekher <[email protected]>
Sergio Rubio <[email protected]>
Hengfei Yang <[email protected]>
19 changes: 17 additions & 2 deletions search/collector/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,28 @@ func NewAllCollector() *AllCollector {

func (a *AllCollector) Collect(ctx context.Context, aggs search.Aggregations,
searcher search.Collectible) (search.DocumentMatchIterator, error) {
return &AllIterator{
iter := &AllIterator{
ctx: ctx,
neededFields: aggs.Fields(),
bucket: search.NewBucket("", aggs),
searcher: searcher,
searchContext: search.NewSearchContext(searcher.DocumentMatchPoolSize(), 0),
}, nil
}
if len(iter.neededFields) <= 1 {
return iter, nil
}

// filter repeat field
store := make(map[string]struct{}, len(iter.neededFields))
for _, field := range iter.neededFields {
store[field] = struct{}{}
}
iter.neededFields = iter.neededFields[:0]
for field := range store {
iter.neededFields = append(iter.neededFields, field)
}

return iter, nil
}

func (a *AllCollector) Size() int {
Expand Down
13 changes: 13 additions & 0 deletions search/collector/topn.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ func (hc *TopNCollector) Collect(ctx context.Context, aggs search.Aggregations,

// add fields needed by aggregations
hc.neededFields = append(hc.neededFields, aggs.Fields()...)

// filter repeat field
if len(hc.neededFields) > 1 {
store := make(map[string]struct{}, len(hc.neededFields))
for _, field := range hc.neededFields {
store[field] = struct{}{}
}
hc.neededFields = hc.neededFields[:0]
for field := range store {
hc.neededFields = append(hc.neededFields, field)
}
}

bucket := search.NewBucket("", aggs)

var hitNumber int
Expand Down