Skip to content

Commit

Permalink
Gère le cas où les résultats de la recherche ne contiennent pas de hi…
Browse files Browse the repository at this point in the history
…ghlight
  • Loading branch information
philippemilink authored and Situphen committed Oct 30, 2024
1 parent f94bfd5 commit f183502
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions zds/search/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def test_basic_search(self):
) # … and only of the right type …
self.assertEqual(r["document"]["id"], ids[doc_type][i]) # … with the right id !

# Search with a query which returns results, but without highlights:
result = self.client.get(reverse("search:query") + "?q=-c", follow=False)
self.assertEqual(result.status_code, 200)

def test_search_many_pages(self):
if not self.manager.connected:
return
Expand Down
3 changes: 2 additions & 1 deletion zds/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ def get_queryset(self):
if "text_match" in entry:
entry["collection"] = search_collections[i]
entry["document"]["final_score"] = entry["text_match"] * entry["document"]["weight"]
entry["document"]["highlights"] = entry["highlights"][0]
if len(entry["highlights"]) > 0:
entry["document"]["highlights"] = entry["highlights"][0]

if "tags" in entry["document"] and "tag_slugs" in entry["document"]:
assert len(entry["document"]["tags"]) == len(entry["document"]["tag_slugs"])
Expand Down

0 comments on commit f183502

Please sign in to comment.