Fixed issue #2195 - Search with id:123 does not work anymore (fixes #2195)

This commit is contained in:
Billy Zhou 2018-10-02 19:50:50 +08:00
parent f15ac3be7e
commit bfccecc012
2 changed files with 27 additions and 10 deletions

View file

@ -347,6 +347,7 @@ return search result
'query_string' => { 'query_string' => {
'query' => append_wildcard_to_simple_query(query), 'query' => append_wildcard_to_simple_query(query),
'default_operator' => 'AND', 'default_operator' => 'AND',
'analyze_wildcard' => true,
} }
} }
data['query']['bool']['must'].push condition data['query']['bool']['must'].push condition
@ -728,10 +729,10 @@ return true if backend is configured
result result
end end
# add * on simple query like "somephrase23" or "attribute: somephrase23" # add * on simple query like "somephrase23"
def self.append_wildcard_to_simple_query(query) def self.append_wildcard_to_simple_query(query)
query.strip! query.strip!
query += '*' if query.match?(/^([[:alnum:]._]+|[[:alnum:]]+\:\s*[[:alnum:]._]+)$/) query += '*' if !query.match?(/:/)
query query
end end
end end

View file

@ -28,6 +28,22 @@ class SearchIndexBackendTest < ActiveSupport::TestCase
article.from: bob # also article.from can be used article.from: bob # also article.from can be used
article.body: heat~ # using the fuzzy operator will also find terms that are similar, in this case also “head” article.body: heat~ # using the fuzzy operator will also find terms that are similar, in this case also “head”
article.body: /joh?n(ath[oa]n)/ # using regular expressions article.body: /joh?n(ath[oa]n)/ # using regular expressions
user:M
user:Max
user:Max.
user:Max*
organization:A_B
organization:A_B*
user: M
user: Max
user: Max.
user: Max*
organization: A_B
organization: A_B*
id:123
number:123
id:"123"
number:"123"
) )
simple_queries = clean_queries %( simple_queries = clean_queries %(
@ -38,14 +54,14 @@ class SearchIndexBackendTest < ActiveSupport::TestCase
A_B A_B
äöü äöü
123 123
user:M *ax # wildcards are allowed in simple queries
user:Max Max*
user:Max. M*x
organization:A_B M?x
user: M test@example.com
user: Max test@example.
user: Max. test@example
organization: A_B test@
) )
complex_queries.each do |query| complex_queries.each do |query|