From 59aaa20e291e9202632b6028bf814113893ef800 Mon Sep 17 00:00:00 2001 From: Arnaud-D <35631001+Arnaud-D@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:55:17 +0100 Subject: [PATCH] =?UTF-8?q?Met=20=C3=A0=20jour=20les=20poids=20de=20recher?= =?UTF-8?q?che?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- doc/source/back-end/search.rst | 7 +++---- zds/search/tests/tests_views.py | 12 ++++++------ zds/settings/abstract_base/zds.py | 5 ++--- zds/tutorialv2/models/database.py | 24 +++++++++++------------- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/doc/source/back-end/search.rst b/doc/source/back-end/search.rst index 110244e099..8637090f35 100644 --- a/doc/source/back-end/search.rst +++ b/doc/source/back-end/search.rst @@ -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, diff --git a/zds/search/tests/tests_views.py b/zds/search/tests/tests_views.py index 6bfaad1aa7..ac75679fc2 100644 --- a/zds/search/tests/tests_views.py +++ b/zds/search/tests/tests_views.py @@ -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() @@ -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() @@ -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. @@ -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() @@ -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() diff --git a/zds/settings/abstract_base/zds.py b/zds/settings/abstract_base/zds.py index a242c2a1d6..0c5b40bb38 100644 --- a/zds/settings/abstract_base/zds.py +++ b/zds/settings/abstract_base/zds.py @@ -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, diff --git a/zds/tutorialv2/models/database.py b/zds/tutorialv2/models/database.py index 8f0a50ddb2..cd73182b1a 100644 --- a/zds/tutorialv2/models/database.py +++ b/zds/tutorialv2/models/database.py @@ -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"]