From bfccecc0122bc76e5e627455e312df3aaf70743c Mon Sep 17 00:00:00 2001 From: Billy Zhou Date: Tue, 2 Oct 2018 19:50:50 +0800 Subject: [PATCH] Fixed issue #2195 - Search with id:123 does not work anymore (fixes #2195) --- lib/search_index_backend.rb | 5 ++-- test/unit/search_index_backend_test.rb | 32 +++++++++++++++++++------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/search_index_backend.rb b/lib/search_index_backend.rb index f1735c172..725bf7995 100644 --- a/lib/search_index_backend.rb +++ b/lib/search_index_backend.rb @@ -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 diff --git a/test/unit/search_index_backend_test.rb b/test/unit/search_index_backend_test.rb index f1eb8648b..94b404dee 100644 --- a/test/unit/search_index_backend_test.rb +++ b/test/unit/search_index_backend_test.rb @@ -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|