diff --git a/openedx/core/djangoapps/content/search/documents.py b/openedx/core/djangoapps/content/search/documents.py index ab73123d7572..6a6c920a71db 100644 --- a/openedx/core/djangoapps/content/search/documents.py +++ b/openedx/core/djangoapps/content/search/documents.py @@ -28,7 +28,11 @@ class Fields: id = "id" usage_key = "usage_key" type = "type" # DocType.course_block or DocType.library_block (see below) - block_id = "block_id" # The block_id part of the usage key. Sometimes human-readable, sometimes a random hex ID + # The block_id part of the usage key for course or library blocks. + # If it's a collection, the collection.key is stored here. + # Sometimes human-readable, sometimes a random hex ID + # Is only unique within the given context_key. + block_id = "block_id" display_name = "display_name" description = "description" modified = "modified" @@ -54,7 +58,7 @@ class Fields: tags_level1 = "level1" tags_level2 = "level2" tags_level3 = "level3" - # List of collection.key strings this object belongs to. + # List of collection.block_id strings this object belongs to. collections = "collections" # The "content" field is a dictionary of arbitrary data, depending on the block_type. # It comes from each XBlock's index_dictionary() method (if present) plus some processing. @@ -339,6 +343,7 @@ def searchable_doc_for_collection(collection) -> dict: """ doc = { Fields.id: collection.id, + Fields.block_id: collection.key, Fields.type: DocType.collection, Fields.display_name: collection.title, Fields.description: collection.description, diff --git a/openedx/core/djangoapps/content/search/tests/test_api.py b/openedx/core/djangoapps/content/search/tests/test_api.py index e4a004635103..3105ad8c007f 100644 --- a/openedx/core/djangoapps/content/search/tests/test_api.py +++ b/openedx/core/djangoapps/content/search/tests/test_api.py @@ -186,7 +186,8 @@ def setUp(self): description="my collection description" ) self.collection_dict = { - 'id': self.collection.id, + "id": self.collection.id, + "block_id": self.collection.key, "type": "collection", "display_name": "my_collection", "description": "my collection description", @@ -451,6 +452,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch): lib_access, _ = SearchAccess.objects.get_or_create(context_key=self.library.key) doc_collection1_created = { "id": collection1.id, + "block_id": collection1.key, "type": "collection", "display_name": "Collection 1", "description": "First Collection", @@ -464,6 +466,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch): } doc_collection2_created = { "id": collection2.id, + "block_id": collection2.key, "type": "collection", "display_name": "Collection 2", "description": "Second Collection", @@ -477,6 +480,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch): } doc_collection2_updated = { "id": collection2.id, + "block_id": collection2.key, "type": "collection", "display_name": "Collection 2", "description": "Second Collection", @@ -490,6 +494,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch): } doc_collection1_updated = { "id": collection1.id, + "block_id": collection1.key, "type": "collection", "display_name": "Collection 1", "description": "First Collection", diff --git a/openedx/core/djangoapps/content/search/tests/test_documents.py b/openedx/core/djangoapps/content/search/tests/test_documents.py index 990ec4db9dcb..47a89b2068a8 100644 --- a/openedx/core/djangoapps/content/search/tests/test_documents.py +++ b/openedx/core/djangoapps/content/search/tests/test_documents.py @@ -295,6 +295,7 @@ def test_collection_with_library(self): doc = searchable_doc_for_collection(self.collection) assert doc == { "id": self.collection.id, + "block_id": self.collection.key, "type": "collection", "org": "edX", "display_name": "Toy Collection", @@ -325,6 +326,7 @@ def test_collection_with_no_library(self): doc = searchable_doc_for_collection(collection) assert doc == { "id": collection.id, + "block_id": collection.key, "type": "collection", "display_name": "my_collection", "description": "my collection description",