Skip to content

Commit

Permalink
trim leading and trailing whitespaces from search strings
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoRoessner committed Dec 11, 2023
1 parent b781949 commit d265b5d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,26 +821,27 @@ func (this *Query) selectByField(kind string, field string, value string, user s
}

func (this *Query) getFeatureSearchInfo(query string) (operator string, config map[string]interface{}) {
if strings.Contains(query, "*") {
search := strings.TrimSpace(query)
if strings.Contains(search, "*") {
return "wildcard", map[string]interface{}{
"feature_search": map[string]interface{}{"case_insensitive": true, "value": query},
"feature_search": map[string]interface{}{"case_insensitive": true, "value": search},
}
}
if !this.config.EnableCombinedWildcardFeatureSearch || strings.ContainsAny(query, " -/_:,;([{&%$") {
if !this.config.EnableCombinedWildcardFeatureSearch || strings.ContainsAny(search, " -/_:,;([{&%$") {
return "match", map[string]interface{}{
"feature_search": map[string]interface{}{"operator": "AND", "query": query},
"feature_search": map[string]interface{}{"operator": "AND", "query": search},
}
}
return "bool", map[string]interface{}{
"should": []map[string]interface{}{
{
"wildcard": map[string]interface{}{
"feature_search": map[string]interface{}{"case_insensitive": true, "value": "*" + query + "*"},
"feature_search": map[string]interface{}{"case_insensitive": true, "value": "*" + search + "*"},
},
},
{
"match": map[string]interface{}{
"feature_search": map[string]interface{}{"operator": "AND", "query": query},
"feature_search": map[string]interface{}{"operator": "AND", "query": search},
},
},
},
Expand Down

0 comments on commit d265b5d

Please sign in to comment.