From f5b61b4303a1ee5f2ff6af7b68c4bbe9352a938c Mon Sep 17 00:00:00 2001 From: William Dewey Date: Mon, 16 Dec 2024 14:30:37 -0600 Subject: [PATCH] don't try to match up non-string values stopgap fix for https://github.com/CDRH/api/issues/151 --- app/services/search_item_res.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/services/search_item_res.rb b/app/services/search_item_res.rb index b8a70f0..5bb328b 100644 --- a/app/services/search_item_res.rb +++ b/app/services/search_item_res.rb @@ -41,6 +41,7 @@ def combine_highlights def find_source_from_top_hits(top_hits, field, key) # elasticsearch stores nested source results without the "path" + parent = field.split(".").first if field.include?(".") nested_child = field.split(".").last @@ -124,15 +125,18 @@ def reformat_facets end def remove_nonword_chars(term) - + if term.class == Array #ensure that term is a string value, not an array term = term[0] end - # transliterate to ascii (ø -> o) - transliterated = I18n.transliterate(term) - # remove html tags like em, u, and strong, then strip remaining non-alpha characters - transliterated.gsub(/<\/?(?:em|strong|u)>|\W/, "").downcase + if term.class == String + # it should not be a hash, but this is a failsafe + # transliterate to ascii (ø -> o) + transliterated = I18n.transliterate(term) + # remove html tags like em, u, and strong, then strip remaining non-alpha characters + transliterated.gsub(/<\/?(?:em|strong|u)>|\W/, "").downcase + end end def get_buckets(info, field)