From 2e41907448c53bcc13946c9498a419d50e1d3a2a Mon Sep 17 00:00:00 2001 From: Max Magorsch Date: Fri, 10 Jan 2020 00:53:36 +0100 Subject: Fix the useflag search for USE flags with hyphens So far, 'name' was mapped as a 'text'-field in the elasticsearch useflag index. Accordingly, values are analyzed when entering them into elasticsearch. This is favourable, when suggesting useflags for typeahead for instance, as match_phrase_prefix can be used. However, when searching for a specific useflag by name this leads to problems, as for instance searching for gmxapi-legacy returns: - gmxapi-legacy - gmxapi - legacy as the field is analyzed. That's why an additional raw field has been added to the 'name' field using multi-fields. This way name and name.raw can be used as follows: - name is of type text - name.raw is of type keyword Accordingly name.raw can be used when searching for a specific useflag by name, while it is still possible to use name for match_phrase_prefix and typeahead. Please see https://www.elastic.co/guide/en/elasticsearch/reference/ current/multi-fields.html for more details. PLEASE NOTE: As the index has been changed, a new index has to populated after this commit. Signed-off-by: Max Magorsch --- app/repositories/useflag_repository.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/repositories/useflag_repository.rb b/app/repositories/useflag_repository.rb index 8198a9b..2f8034f 100644 --- a/app/repositories/useflag_repository.rb +++ b/app/repositories/useflag_repository.rb @@ -14,7 +14,7 @@ class UseflagRepository < BaseRepository mapping dynamic: 'strict' do indexes :id, type: 'keyword' - indexes :name, type: 'text' + indexes :name, type: 'text', fields: { raw: { type: "keyword" } } indexes :description, type: 'text' indexes :atom, type: 'keyword' indexes :scope, type: 'keyword' @@ -27,7 +27,7 @@ class UseflagRepository < BaseRepository def get_flags(name) result = { local: {}, global: [], use_expand: [] } - find_all_by(:name, name).each do |flag| + find_all_by("name.raw", name).each do |flag| case flag.scope when 'local' result[:local][flag.atom] = flag -- cgit v1.2.3-65-gdbad