Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Use top-level `keyword` fields instead of subfields (#3161)
Dhruv Bhanushalidf51293d940e
diff --git a/api/api/controllers/search_controller.py b/api/api/controllers/search_controller.pyindex b576769e2..045cf5937 100644--- a/api/api/controllers/search_controller.py+++ b/api/api/controllers/search_controller.py@@ -350,12 +350,14 @@ def search(("extension", None),("category", None),("categories", "category"),+ ("source", None),+ ("license", None),+ ("license_type", "license"),+ # Audio-specific filters("length", None),+ # Image-specific filters("aspect_ratio", None),("size", None),- ("source", None),- ("license", "license__keyword"),- ("license_type", "license__keyword"),]for serializer_field, es_field in filters:if serializer_field in search_params.data:@@ -512,9 +514,7 @@ def related_media(uuid: str, index: str, filter_dead: bool) -> list[Hit]:# Search the default index for the item itself as it might be sensitive.item_search = Search(index=index)- # TODO: remove `__keyword` after- # https://github.com/WordPress/openverse/pull/3143 is merged.- item_hit = item_search.query(Term(identifier__keyword=uuid)).execute().hits[0]+ item_hit = item_search.query(Term(identifier=uuid)).execute().hits[0]# Match related using title.title = getattr(item_hit, "title", None)@@ -539,9 +539,7 @@ def related_media(uuid: str, index: str, filter_dead: bool) -> list[Hit]:s = Search(index=f"{index}-filtered")# Exclude the current item and mature content.- # TODO: remove `__keyword` after- # https://github.com/WordPress/openverse/pull/3143 is merged.- s = s.query(related_query & ~Term(identifier__keyword=uuid) & ~Term(mature=True))+ s = s.query(related_query & ~Term(identifier=uuid) & ~Term(mature=True))# Exclude the dynamically disabled sources.s = _exclude_filtered(s)@@ -579,7 +577,7 @@ def get_sources(index):aggs = {"unique_sources": {"terms": {- "field": "source.keyword",+ "field": "source","size": size,"order": {"_key": "desc"},}diff --git a/api/api/utils/search_context.py b/api/api/utils/search_context.pyindex d1505c476..d733df801 100644--- a/api/api/utils/search_context.py+++ b/api/api/utils/search_context.py@@ -35,13 +35,7 @@ class SearchContext:# Use `identifier` rather than the document `id` due to# `id` instability between refreshes:# https://github.com/WordPress/openverse/issues/2306- # `identifier` is mapped as `text` which will match fuzzily.- # Use `identifier.keyword` to match _exactly_- # cf: https://github.com/WordPress/openverse/issues/2154- Q(- "terms",- **{"identifier.keyword": all_result_identifiers},- )+ Q("terms", identifier=all_result_identifiers))# The default query size is 10, so we need to slice the querydiff --git a/ingestion_server/ingestion_server/elasticsearch_models.py b/ingestion_server/ingestion_server/elasticsearch_models.pyindex 32fc8491c..c758d847e 100644--- a/ingestion_server/ingestion_server/elasticsearch_models.py+++ b/ingestion_server/ingestion_server/elasticsearch_models.py@@ -199,7 +199,7 @@ class Media(SyncableDocType):@staticmethoddef parse_detailed_tags(json_tags):if not json_tags:- return None+ return []parsed_tags = []for tag in json_tags:if "name" in tag: