Skip to content

Commit

Permalink
fix: store collection.key in the document block_id field
Browse files Browse the repository at this point in the history
  • Loading branch information
pomegranited committed Sep 12, 2024
1 parent eb78583 commit 5bdcc9e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
9 changes: 7 additions & 2 deletions openedx/core/djangoapps/content/search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion openedx/core/djangoapps/content/search/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 5bdcc9e

Please sign in to comment.