related: Fix toLower

Don't change the slice.

Fixes #7198
This commit is contained in:
Bjørn Erik Pedersen 2020-04-21 17:44:48 +02:00
parent b3c825756f
commit 27af5a339a
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
2 changed files with 20 additions and 2 deletions

View file

@ -274,9 +274,12 @@ func (cfg IndexConfig) ToKeywords(v interface{}) ([]Keyword, error) {
keywords = append(keywords, StringKeyword(vv)) keywords = append(keywords, StringKeyword(vv))
case []string: case []string:
if toLower { if toLower {
for i := 0; i < len(vv); i++ { vc := make([]string, len(vv))
vv[i] = strings.ToLower(vv[i]) copy(vc, vv)
for i := 0; i < len(vc); i++ {
vc[i] = strings.ToLower(vc[i])
} }
vv = vc
} }
keywords = append(keywords, StringsToKeywords(vv...)...) keywords = append(keywords, StringsToKeywords(vv...)...)
case time.Time: case time.Time:

View file

@ -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) { func BenchmarkRelatedNewIndex(b *testing.B) {
pages := make([]*testDoc, 100) pages := make([]*testDoc, 100)