Skip to content

Commit

Permalink
Met à jour les poids de recherche
Browse files Browse the repository at this point in the history
* distingue principalement validé ou non
* distingue les multipages de manière unifiée pour les contenus validés (identique pour article ou tuto)
* garde la distinction choisi/non choisi pour les billets
  • Loading branch information
Arnaud-D committed Nov 6, 2024
1 parent a6ae90d commit 59aaa20
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
7 changes: 3 additions & 4 deletions doc/source/back-end/search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,10 @@ Il est possible de modifier les différents paramètres de la recherche dans
"boosts": {
"publishedcontent": {
"global": global_weight_publishedcontent,
"if_article": 2.0, # s'il s'agit d'un article
"if_tutorial": 2.0, # s'il s'agit d'un tuto
"if_medium_or_big_tutorial": 2.5, # s'il s'agit d'un tuto d'une taille plutôt importante
"if_validated": 2.0, # s'il s'agit d'une publication validée (article ou tuto)
"if_validated_and_multipage": 2.5, # s'il s'agit d'une publication validée sur plusieurs page (medium ou big-tuto)
"if_opinion": 1.66, # s'il s'agit d'un billet
"if_opinion_not_picked": 1.5, # s'il s'agit d'un billet pas mis en avant
"if_opinion_not_picked": 1.5, # s'il s'agit d'un billet non mis en avant sur la page d'accueil
# poids des différents champs :
"title": global_weight_publishedcontent * 3,
Expand Down
12 changes: 6 additions & 6 deletions zds/search/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def test_boosts(self):
== response[3]["document"]["weight"]
)

settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_article"] = 2.0
settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_validated"] = 2.0

# Reindex to update the weight
self._index_everything()
Expand All @@ -650,8 +650,8 @@ def test_boosts(self):
self.assertTrue(response[0]["document"]["weight"] > response[1]["document"]["weight"])
self.assertEqual(response[0]["document"]["id"], str(published_article.pk)) # obvious

settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_article"] = 1.0
settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_medium_or_big_tutorial"] = 2.0
settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_validated"] = 1.0
settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_validated_and_multipage"] = 2.0

# Reindex to update the weight
self._index_everything()
Expand All @@ -665,7 +665,7 @@ def test_boosts(self):
self.assertTrue(response[0]["document"]["weight"] > response[1]["document"]["weight"])
self.assertEqual(response[0]["document"]["id"], str(published_tuto.pk)) # obvious

settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_medium_or_big_tutorial"] = 1.0
settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_validated_and_multipage"] = 1.0
settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_opinion"] = 2.0
settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_opinion_not_picked"] = 4.0
# Note: in "real life", unpicked opinion would get a boost < 1.
Expand All @@ -689,7 +689,7 @@ def test_boosts(self):

settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_opinion"] = 1.0
settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_opinion_not_picked"] = 1.0
settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_medium_or_big_tutorial"] = 2.0
settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_validated_and_multipage"] = 2.0

# Reindex to update the weight
self._index_everything()
Expand All @@ -703,7 +703,7 @@ def test_boosts(self):
self.assertTrue(response[0]["document"]["weight"] > response[1]["document"]["weight"])
self.assertEqual(response[0]["document"]["id"], str(published_tuto.pk)) # obvious

settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_medium_or_big_tutorial"] = 1.0
settings.ZDS_APP["search"]["boosts"]["publishedcontent"]["if_validated_and_multipage"] = 1.0

# Reindex to update the weight
self._index_everything()
Expand Down
5 changes: 2 additions & 3 deletions zds/settings/abstract_base/zds.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,8 @@
"boosts": {
"publishedcontent": {
"global": global_weight_publishedcontent,
"if_article": global_weight_publishedcontent * 1.5,
"if_tutorial": global_weight_publishedcontent * 1.5,
"if_medium_or_big_tutorial": global_weight_publishedcontent * 1.7,
"if_validated": global_weight_publishedcontent * 1.5,
"if_validated_and_multipage": global_weight_publishedcontent * 1.7,
"if_opinion": global_weight_publishedcontent * 1.3,
"if_opinion_not_picked": global_weight_publishedcontent * 1.1,
"title": global_weight_publishedcontent * 4,
Expand Down
24 changes: 11 additions & 13 deletions zds/tutorialv2/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,29 +1135,27 @@ def get_document_source(self, excluded_fields=[]):
if versioned.has_extracts():
data["text"] = clean_html(versioned.get_content_online())

is_medium_big_tutorial = versioned.has_sub_containers()
data["weight"] = self._compute_search_weight(is_medium_big_tutorial)
is_multipage = versioned.has_sub_containers()
data["weight"] = self._get_search_weight(is_multipage)

return data

def _compute_search_weight(self, is_medium_big_tutorial: bool):
def _get_search_weight(self, is_multipage: bool):
"""
This function calculates a weight for publishedcontent in order to sort them according to different boosts.
There is a boost according to the type of content (article, opinion, tutorial),
if it is a big tutorial or if it is picked.
Calculate the weight used to sort search results.
We make a difference between validated content (either single or multipage) and content published freely
(picked for the front page or not).
"""
weights = settings.ZDS_APP["search"]["boosts"]["publishedcontent"]

if self.content_type == "ARTICLE":
return weights["if_article"]
elif self.content_type == "TUTORIAL":
if is_medium_big_tutorial:
return weights["if_medium_or_big_tutorial"]
if self.content.requires_validation():
if is_multipage:
return weights["if_validated_and_multipage"]
else:
return weights["if_tutorial"]
return weights["if_validated"]
else:
assert self.content_type == "OPINION"
if self.content.sha_picked is not None:
if self.content.is_picked():
return weights["if_opinion"]
else:
return weights["if_opinion_not_picked"]
Expand Down

0 comments on commit 59aaa20

Please sign in to comment.