Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : Belga-Archive API : Search highlighted text is not showing properly with boolean operators [SDBELGA-736] #434

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/belga/search_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def get_search_text(self, query):
return searchText

def set_highlight(self, search_text, docs):
search_text = "|".join(search_text.split())
search_text = "|".join(re.escape(term.strip()) for term in search_text.split())
fields = ("body_html", "headline", "slugline")
for doc in docs:
for field in fields:
Expand Down
2 changes: 1 addition & 1 deletion server/tests/fixtures/belga-360archive-search.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "",
"credit": "BELGA",
"topic": "Belga 360 slugline",
"headLine": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"headLine": "(Lorem ipsum) dolor sit amet, consectetur adipiscing elit.",
"keywords": ["BRIEF", "#CORONAVIRUS", "SPORTS", "INTERNET"],
"authors": [
{
Expand Down
25 changes: 22 additions & 3 deletions server/tests/search_providers/belga_360_archive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def test_format_list_item(self):
self.assertEqual(item["guid"], guid)
self.assertEqual(item["extra"]["city"], "Bruxelles")
self.assertEqual(
item["headline"], "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
item["headline"],
"(Lorem ipsum) dolor sit amet, consectetur adipiscing elit.",
)
self.assertEqual(item["name"], "")
self.assertEqual(item["slugline"], "Belga 360 slugline")
Expand Down Expand Up @@ -400,7 +401,7 @@ def test_get_highlighted_text(self):
{
"headline": [
(
'<span class="es-highlight">Lorem</span> <span class="es-highlight">ipsum</span> dolor '
'(<span class="es-highlight">Lorem</span> <span class="es-highlight">ipsum</span>) dolor '
"sit amet, consectetur adipiscing elit."
)
]
Expand All @@ -415,7 +416,25 @@ def test_get_highlighted_text(self):
{
"headline": [
(
'<span class="es-highlight">Lorem</span> <span class="es-highlight">ipsum</span> dolor '
'(<span class="es-highlight">Lorem</span> <span class="es-highlight">ipsum</span>) dolor '
"sit amet, consectetur adipiscing elit."
)
]
},
)

query["query"]["filtered"]["query"]["query_string"][
"query"
] = "(Lorem ipsum)"
items = self.provider.find(query)
highlighted_item = items[0]

self.assertEqual(
highlighted_item["es_highlight"],
{
"headline": [
(
'<span class="es-highlight">(Lorem</span> <span class="es-highlight">ipsum)</span> dolor '
"sit amet, consectetur adipiscing elit."
)
]
Expand Down