Skip to content

Commit

Permalink
related: Fix toLower
Browse files Browse the repository at this point in the history
Don't change the slice.

Fixes #7198
  • Loading branch information
bep committed Apr 21, 2020
1 parent b3c8257 commit 27af5a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions related/inverted_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,12 @@ func (cfg IndexConfig) ToKeywords(v interface{}) ([]Keyword, error) {
keywords = append(keywords, StringKeyword(vv))
case []string:
if toLower {
for i := 0; i < len(vv); i++ {
vv[i] = strings.ToLower(vv[i])
vc := make([]string, len(vv))
copy(vc, vv)
for i := 0; i < len(vc); i++ {
vc[i] = strings.ToLower(vc[i])
}
vv = vc
}
keywords = append(keywords, StringsToKeywords(vv...)...)
case time.Time:
Expand Down
15 changes: 15 additions & 0 deletions related/inverted_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ func TestSearch(t *testing.T) {

}

func TestToKeywordsToLower(t *testing.T) {
c := qt.New(t)
slice := []string{"A", "B", "C"}
config := IndexConfig{ToLower: true}
keywords, err := config.ToKeywords(slice)
c.Assert(err, qt.IsNil)
c.Assert(slice, qt.DeepEquals, []string{"A", "B", "C"})
c.Assert(keywords, qt.DeepEquals, []Keyword{
StringKeyword("a"),
StringKeyword("b"),
StringKeyword("c"),
})

}

func BenchmarkRelatedNewIndex(b *testing.B) {

pages := make([]*testDoc, 100)
Expand Down

0 comments on commit 27af5a3

Please sign in to comment.