From a7757d7e6ed4d02dc2f88dca80fbdae4b3c397d0 Mon Sep 17 00:00:00 2001 From: XnpioChV Date: Mon, 17 Jun 2024 11:04:28 -0500 Subject: [PATCH 1/2] feat: implicitCount added to content search index --- openedx/core/djangoapps/content/search/documents.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/openedx/core/djangoapps/content/search/documents.py b/openedx/core/djangoapps/content/search/documents.py index dea494f312f0..0ea76a358418 100644 --- a/openedx/core/djangoapps/content/search/documents.py +++ b/openedx/core/djangoapps/content/search/documents.py @@ -41,6 +41,7 @@ class Fields: # For details on the format of the hierarchical tag data. # We currently have a hard-coded limit of 4 levels of tags in the search index (level0..level3). tags = "tags" + tags_count = "implicit_count" tags_taxonomy = "taxonomy" # subfield of tags, i.e. tags.taxonomy tags_level0 = "level0" # subfield of tags, i.e. tags.level0 tags_level1 = "level1" @@ -183,9 +184,14 @@ def _tags_for_content_object(object_id: UsageKey | LearningContextKey) -> dict: # Clear out tags in the index when unselecting all tags for the block, otherwise # it would remain the last value if a cleared Fields.tags field is not included return {Fields.tags: {}} + tags_count = tagging_api.get_object_tag_counts(str(object_id), count_implicit=True) + tag_count = 0 + if str(object_id) in tags_count: + tag_count = tags_count[str(object_id)] result = { Fields.tags_taxonomy: [], Fields.tags_level0: [], + Fields.tags_count: tag_count, # ... other levels added as needed } for obj_tag in all_tags: From fbf97f11ddfca2b87cf3d224889dc596a42b6499 Mon Sep 17 00:00:00 2001 From: XnpioChV Date: Mon, 17 Jun 2024 11:37:13 -0500 Subject: [PATCH 2/2] test: Added for new implicit_count field on search content index --- openedx/core/djangoapps/content/search/tests/test_api.py | 4 ++++ .../core/djangoapps/content/search/tests/test_documents.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/openedx/core/djangoapps/content/search/tests/test_api.py b/openedx/core/djangoapps/content/search/tests/test_api.py index 1c78b28506fe..c004613d4158 100644 --- a/openedx/core/djangoapps/content/search/tests/test_api.py +++ b/openedx/core/djangoapps/content/search/tests/test_api.py @@ -209,6 +209,7 @@ def test_index_xblock_tags(self, mock_meilisearch): doc_sequential_with_tags1 = { "id": self.doc_sequential["id"], "tags": { + 'implicit_count': 2, 'taxonomy': ['A'], 'level0': ['A > one', 'A > two'] } @@ -216,6 +217,7 @@ def test_index_xblock_tags(self, mock_meilisearch): doc_sequential_with_tags2 = { "id": self.doc_sequential["id"], "tags": { + 'implicit_count': 4, 'taxonomy': ['A', 'B'], 'level0': ['A > one', 'A > two', 'B > four', 'B > three'] } @@ -263,6 +265,7 @@ def test_index_library_block_tags(self, mock_meilisearch): doc_problem_with_tags1 = { "id": self.doc_problem["id"], "tags": { + 'implicit_count': 2, 'taxonomy': ['A'], 'level0': ['A > one', 'A > two'] } @@ -270,6 +273,7 @@ def test_index_library_block_tags(self, mock_meilisearch): doc_problem_with_tags2 = { "id": self.doc_problem["id"], "tags": { + 'implicit_count': 4, 'taxonomy': ['A', 'B'], 'level0': ['A > one', 'A > two', 'B > four', 'B > three'] } diff --git a/openedx/core/djangoapps/content/search/tests/test_documents.py b/openedx/core/djangoapps/content/search/tests/test_documents.py index e853fd425273..56ae0a3e3562 100644 --- a/openedx/core/djangoapps/content/search/tests/test_documents.py +++ b/openedx/core/djangoapps/content/search/tests/test_documents.py @@ -120,6 +120,7 @@ def test_problem_block(self): # and https://www.algolia.com/doc/api-reference/widgets/hierarchical-menu/js/ # For details on why the hierarchical tag data is in this format. "tags": { + "implicit_count": 1, "taxonomy": ["Difficulty"], "level0": ["Difficulty > Easy"], }, @@ -162,6 +163,7 @@ def test_html_block(self): ), }, "tags": { + "implicit_count": 6, "taxonomy": ["Difficulty", "Subject"], "level0": ["Difficulty > Normal", "Subject > Hypertext", "Subject > Linguistics"], "level1": ["Subject > Hypertext > Jump Links", "Subject > Linguistics > Asian Languages"],