From 009123a019adac2cada670f41f28c520cfea5b9e Mon Sep 17 00:00:00 2001 From: Braden MacDonald Date: Thu, 6 Jun 2024 17:00:48 -0700 Subject: [PATCH] fix: searching tag refinement was sometimes not working (#34935) --- openedx/core/djangoapps/content/search/api.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/content/search/api.py b/openedx/core/djangoapps/content/search/api.py index f658155eb812..17824dbc2a7e 100644 --- a/openedx/core/djangoapps/content/search/api.py +++ b/openedx/core/djangoapps/content/search/api.py @@ -325,11 +325,20 @@ def rebuild_index(status_cb: Callable[[str], None] | None = None) -> None: ]) # Mark which attributes are used for keyword search, in order of importance: client.index(temp_index_name).update_searchable_attributes([ + # Keyword search does _not_ search the course name, course ID, breadcrumbs, block type, or other fields. Fields.display_name, Fields.block_id, Fields.content, Fields.tags, - # Keyword search does _not_ search the course name, course ID, breadcrumbs, block type, or other fields. + # If we don't list the following sub-fields _explicitly_, they're only sometimes searchable - that is, they + # are searchable only if at least one document in the index has a value. If we didn't list them here and, + # say, there were no tags.level3 tags in the index, the client would get an error if trying to search for + # these sub-fields: "Attribute `tags.level3` is not searchable." + Fields.tags + "." + Fields.tags_taxonomy, + Fields.tags + "." + Fields.tags_level0, + Fields.tags + "." + Fields.tags_level1, + Fields.tags + "." + Fields.tags_level2, + Fields.tags + "." + Fields.tags_level3, ]) ############## Libraries ##############