aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <max@magorsch.de>2020-01-10 00:53:36 +0100
committerMax Magorsch <max@magorsch.de>2020-01-10 00:53:36 +0100
commit2e41907448c53bcc13946c9498a419d50e1d3a2a (patch)
treee34f69bc0ded13fa13e49becdb8e58033eb5e7e3
parentFix the default search behaviour (diff)
downloadpackages-5-2e41907448c53bcc13946c9498a419d50e1d3a2a.tar.gz
packages-5-2e41907448c53bcc13946c9498a419d50e1d3a2a.tar.bz2
packages-5-2e41907448c53bcc13946c9498a419d50e1d3a2a.zip
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 <max@magorsch.de>
-rw-r--r--app/repositories/useflag_repository.rb4
1 files 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