This commit is contained in:
parent
f15ac3be7e
commit
bfccecc012
2 changed files with 27 additions and 10 deletions
|
@ -347,6 +347,7 @@ return search result
|
|||
'query_string' => {
|
||||
'query' => append_wildcard_to_simple_query(query),
|
||||
'default_operator' => 'AND',
|
||||
'analyze_wildcard' => true,
|
||||
}
|
||||
}
|
||||
data['query']['bool']['must'].push condition
|
||||
|
@ -728,10 +729,10 @@ return true if backend is configured
|
|||
result
|
||||
end
|
||||
|
||||
# add * on simple query like "somephrase23" or "attribute: somephrase23"
|
||||
# add * on simple query like "somephrase23"
|
||||
def self.append_wildcard_to_simple_query(query)
|
||||
query.strip!
|
||||
query += '*' if query.match?(/^([[:alnum:]._]+|[[:alnum:]]+\:\s*[[:alnum:]._]+)$/)
|
||||
query += '*' if !query.match?(/:/)
|
||||
query
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,6 +28,22 @@ class SearchIndexBackendTest < ActiveSupport::TestCase
|
|||
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: /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 %(
|
||||
|
@ -38,14 +54,14 @@ class SearchIndexBackendTest < ActiveSupport::TestCase
|
|||
A_B
|
||||
äöü
|
||||
123
|
||||
user:M
|
||||
user:Max
|
||||
user:Max.
|
||||
organization:A_B
|
||||
user: M
|
||||
user: Max
|
||||
user: Max.
|
||||
organization: A_B
|
||||
*ax # wildcards are allowed in simple queries
|
||||
Max*
|
||||
M*x
|
||||
M?x
|
||||
test@example.com
|
||||
test@example.
|
||||
test@example
|
||||
test@
|
||||
)
|
||||
|
||||
complex_queries.each do |query|
|
||||
|
|
Loading…
Reference in a new issue