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

feat: implicitCount added to content search index #35000

Closed
Closed
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
6 changes: 6 additions & 0 deletions openedx/core/djangoapps/content/search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions openedx/core/djangoapps/content/search/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,15 @@ 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']
}
}
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']
}
Expand Down Expand Up @@ -263,13 +265,15 @@ 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']
}
}
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']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
},
Expand Down Expand Up @@ -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"],
Expand Down
Loading