Skip to content

Commit

Permalink
Fixed case insensitive querying
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiaswangblad committed Sep 19, 2022
1 parent 1183319 commit 7ddff7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions scan_explorer_service/tests/test_search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def test_parse_query(self):
final_query, _ = parse_query_string('volume:[1 TO 5]')
self.assertEqual(final_query, 'volume_int:[1 TO 5]')

final_query, _ = parse_query_string('PageColor:grAYsCaLe')
self.assertEqual(final_query, 'page_color:Grayscale')


if __name__ == '__main__':
unittest.main()
9 changes: 7 additions & 2 deletions scan_explorer_service/utils/search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,24 @@ def parse_query_string(qs):
#Remove all parameter from the original search to be able to handle the free search
qs_only_free = qs_only_free.replace(kv, "")
if len(kv_arr) == 2:
qs_dict[kv_arr[0]] = kv_arr[1].strip()
qs_dict[kv_arr[0].lower()] = kv_arr[1].strip()
#If the option have qutoes we remove them from the free. Previous removal would than have failed
alt_kv = kv_arr[0] + ':"' + kv_arr[1] + '"'
qs_only_free = qs_only_free.replace(alt_kv, '')

check_query(qs_dict)
#Adds a () around each free search to force OS to look for each individual entry against all default fields
for parameter in re.split('\s+', qs_only_free):
if parameter.upper() not in ['AND', 'OR', '']:
qs = qs.replace(str(parameter), "(" + str(parameter) + ")")

for key in qs_dict.keys():
#Translate input on the keys to the dedicated OS columns
qs = qs.replace(key, query_translations[key])
insensitive_replace = re.compile(re.escape(key), re.IGNORECASE)
qs = insensitive_replace.sub(query_translations[key.lower()], qs)

insensitive_replace = re.compile(re.escape(qs_dict[key]), re.IGNORECASE)
qs = insensitive_replace.sub(qs_dict[key], qs)

return qs, qs_dict

Expand Down

0 comments on commit 7ddff7e

Please sign in to comment.