diff --git a/api/api/admin/media_report.py b/api/api/admin/media_report.py
index 85fccca26f3..971c840a87f 100644
--- a/api/api/admin/media_report.py
+++ b/api/api/admin/media_report.py
@@ -292,11 +292,36 @@ def has_sensitive_text(self, obj):
change_list_template = "admin/api/media/change_list.html"
list_display = ("identifier",)
list_display_links = ("identifier",)
- search_fields = _production_deferred("identifier")
+ search_fields = (None,) # Search functionality is overridden below.
+ search_help_text = format_html(
+ """
+
+ You can use query string syntax for advanced search.
+ You can use "
to wrap phrases and ?
, *
as wildcards.
+
+
+ Examples
+
+ - Search all indexed fields in the model:
Animal
+ - Search for an identifier:
3b858852-67df-44e1-8d57-683991d3ec67
+ -
+ Search for a creator:
creator:Al
+ When searching by creator, make sure to select a single provider using the filters in the sidebar.
+
+ - Search for a tag name:
tags.name:cat
+
+
+ """,
+ "https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax",
+ )
sortable_by = () # Ordering is defined in ``get_queryset``.
def get_list_filter(self, request):
- return (get_pending_record_filter(self.media_type),)
+ return (
+ "source",
+ "provider",
+ get_pending_record_filter(self.media_type),
+ )
def get_list_display(self, request):
if request.GET.get("pending_record_count") != "all":
@@ -313,6 +338,23 @@ def get_list_display(self, request):
"provider",
)
+ def get_search_results(self, request, queryset, search_term):
+ """
+ Override admin search to use Elasticsearch.
+
+ This enables the admin to make complex search queries using
+ query string syntax, that would not normally be possible with
+ Django's native search.
+ """
+
+ if not search_term:
+ return queryset, False
+
+ search = Search(index=settings.MEDIA_INDEX_MAPPING[self.media_type])
+ search = search.query("query_string", query=search_term)
+ identifiers = (hit.identifier for hit in search.scan())
+ return queryset.filter(identifier__in=identifiers), False
+
def total_report_count(self, obj):
return obj.total_report_count