Skip to content

Commit

Permalink
Merge pull request #32 from voldyman/master
Browse files Browse the repository at this point in the history
Initialize aggregations map in AllMatches search, fixes #31
  • Loading branch information
mschoch authored Oct 3, 2020
2 parents 95411bd + 4a91000 commit e32d4b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
# Please keep the list sorted.

Marty Schoch <[email protected]>
Akshay Shekher <[email protected]>
3 changes: 2 additions & 1 deletion search.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ type AllMatches struct {
func NewAllMatches(q Query) *AllMatches {
return &AllMatches{
BaseSearch: BaseSearch{
query: q,
query: q,
aggregations: make(search.Aggregations),
},
}
}
Expand Down
10 changes: 10 additions & 0 deletions search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strconv"
"testing"

"github.com/blugelabs/bluge/search/aggregations"
"github.com/blugelabs/bluge/search/highlight"

"github.com/blugelabs/bluge/analysis/char"
Expand Down Expand Up @@ -1261,3 +1262,12 @@ func TestSearchHighlightingWithRegexpReplacement(t *testing.T) {
t.Fatal(err)
}
}

func TestAllMatchesWithAggregationIssue31(t *testing.T) {
query := NewMatchQuery("bluge").SetField("name")
request := NewAllMatches(query)

// This line would panic because aggregations map was not initialized internally
// should not panic with the fix
request.AddAggregation("score", aggregations.MaxStartingAt(search.DocumentScore(), 0))
}

0 comments on commit e32d4b0

Please sign in to comment.