diff --git a/openedx/core/djangoapps/content/search/documents.py b/openedx/core/djangoapps/content/search/documents.py index 51eca8816430..e45c9fb3f634 100644 --- a/openedx/core/djangoapps/content/search/documents.py +++ b/openedx/core/djangoapps/content/search/documents.py @@ -61,6 +61,10 @@ class Fields: # Text (html) blocks have an "html_content" key in here, capa has "capa_content" and "problem_types", and so on. content = "content" + # Collections use this field to communicate how many entities/components they contain. + # Structural XBlocks may use this one day to indicate how many child blocks they ocntain. + num_children = "num_children" + # Note: new fields or values can be added at any time, but if they need to be indexed for filtering or keyword # search, the index configuration will need to be changed, which is only done as part of the 'reindex_studio' # command (changing those settings on an large active index is not recommended). @@ -344,6 +348,7 @@ def searchable_doc_for_collection(collection) -> dict: # If related contentlibrary is found, it will override this value below. # Mostly contentlibrary.library_key == learning_package.key Fields.context_key: collection.learning_package.key, + Fields.num_children: collection.entities.count(), } # Just in case learning_package is not related to a library try: diff --git a/openedx/core/djangoapps/content/search/tests/test_api.py b/openedx/core/djangoapps/content/search/tests/test_api.py index d075681798bc..ec9975724753 100644 --- a/openedx/core/djangoapps/content/search/tests/test_api.py +++ b/openedx/core/djangoapps/content/search/tests/test_api.py @@ -190,6 +190,7 @@ def setUp(self): "type": "collection", "display_name": "my_collection", "description": "my collection description", + "num_children": 0, "context_key": "lib:org1:lib", "org": "org1", "created": created_date.timestamp(), @@ -453,6 +454,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch): "type": "collection", "display_name": "Collection 1", "description": "First Collection", + "num_children": 0, "context_key": "lib:org1:lib", "org": "org1", "created": created_date.timestamp(), @@ -465,6 +467,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch): "type": "collection", "display_name": "Collection 2", "description": "Second Collection", + "num_children": 0, "context_key": "lib:org1:lib", "org": "org1", "created": created_date.timestamp(), @@ -477,6 +480,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch): "type": "collection", "display_name": "Collection 2", "description": "Second Collection", + "num_children": 1, "context_key": "lib:org1:lib", "org": "org1", "created": created_date.timestamp(), @@ -489,6 +493,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch): "type": "collection", "display_name": "Collection 1", "description": "First Collection", + "num_children": 1, "context_key": "lib:org1:lib", "org": "org1", "created": created_date.timestamp(), diff --git a/openedx/core/djangoapps/content/search/tests/test_documents.py b/openedx/core/djangoapps/content/search/tests/test_documents.py index d972c9ac4956..90ac9c1a70bb 100644 --- a/openedx/core/djangoapps/content/search/tests/test_documents.py +++ b/openedx/core/djangoapps/content/search/tests/test_documents.py @@ -299,6 +299,7 @@ def test_collection_with_library(self): "org": "edX", "display_name": "Toy Collection", "description": "my toy collection description", + "num_children": 1, "context_key": "lib:edX:2012_Fall", "access_id": self.library_access_id, "breadcrumbs": [{"display_name": "some content_library"}], @@ -327,6 +328,7 @@ def test_collection_with_no_library(self): "type": "collection", "display_name": "my_collection", "description": "my collection description", + "num_children": 0, "context_key": learning_package.key, "access_id": self.toy_course_access_id, "breadcrumbs": [{"display_name": "some learning_package"}],