Skip to content

Commit

Permalink
Fix proximity search with quotation
Browse files Browse the repository at this point in the history
  • Loading branch information
tcouch committed Oct 4, 2024
1 parent 1c2e186 commit be1d4dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/rard/research/tests/views/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,14 @@ def do_search(search_function, keywords):
self.assertEqual(do_search(view.fragment_search, "Lorem ~3:5 sit"), [])
self.assertEqual(do_search(view.fragment_search, "Lorem ~3:5 elit"), [])

# Test wildcards work in combination
self.assertEqual(do_search(view.fragment_search, "Lor*m ~3:5 consect*"), [f1])

# Test quotation works
self.assertEqual(
do_search(view.fragment_search, 'Lorem ~3:5 "consectetur adipiscing"'), [f1]
)

def test_search_snippets(self):
raw_content = (
"Lorem ipsum dolor sit amet, <span class='test consectatur'>"
Expand Down
6 changes: 3 additions & 3 deletions src/rard/research/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ def transform_keywords_to_regex(self, keywords):
"""
# Proximity searches have one keyword and contain tilde character
if len(keywords) == 1 and "~" in keywords[0]:
# Remove any '"' characters
kw = keywords[0].replace('"', "")
# Split keyword around proximity search
[(fore, prox_op, aft)] = re.findall(
r"(.*)\s(~\d?:?\d?)\s(.*)", keywords[0]
)
[(fore, prox_op, aft)] = re.findall(r"(.*)\s(~\d?:?\d?)\s(.*)", kw)
# Fore and aft can be multi-word strings containing wildcards so loop back
fore = self.transform_keywords_to_regex([fore])
aft = self.transform_keywords_to_regex([aft])
Expand Down

0 comments on commit be1d4dd

Please sign in to comment.