From f5b20801bc01a2122a68ec5798ef567c40cff22d Mon Sep 17 00:00:00 2001 From: Zack Krida Date: Wed, 7 Sep 2022 13:26:22 -0400 Subject: [PATCH] Init --- api/catalog/api/constants/field_order.py | 1 + api/catalog/api/controllers/search_controller.py | 4 ++++ api/catalog/api/serializers/media_serializers.py | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/api/catalog/api/constants/field_order.py b/api/catalog/api/constants/field_order.py index a67f4b17f..3f3acccbe 100644 --- a/api/catalog/api/constants/field_order.py +++ b/api/catalog/api/constants/field_order.py @@ -5,6 +5,7 @@ json_fields = [ "id", + "created_on", "title", "foreign_landing_url", "url", diff --git a/api/catalog/api/controllers/search_controller.py b/api/catalog/api/controllers/search_controller.py index 1dcb5e90d..87cf84477 100644 --- a/api/catalog/api/controllers/search_controller.py +++ b/api/catalog/api/controllers/search_controller.py @@ -383,6 +383,10 @@ def search( # Route users to the same Elasticsearch worker node to reduce # pagination inconsistencies and increase cache hits. s = s.params(preference=str(ip), request_timeout=7) + + # Sort by new + s = s.sort({"created_on": {"order": "desc"}}) + # Paginate start, end = _get_query_slice(s, page_size, page, filter_dead) s = s[start:end] diff --git a/api/catalog/api/serializers/media_serializers.py b/api/catalog/api/serializers/media_serializers.py index 09d4b003c..0b5712d12 100644 --- a/api/catalog/api/serializers/media_serializers.py +++ b/api/catalog/api/serializers/media_serializers.py @@ -280,6 +280,7 @@ class Meta: model = AbstractMedia fields = [ "id", + "created_on", "title", "foreign_landing_url", "url", @@ -308,6 +309,10 @@ class Meta: source="identifier", ) + created_on = serializers.DateField( + help_text="The timestamp of when the media was added to Openverse.", + ) + tags = TagSerializer( allow_null=True, # replaced with ``[]`` in ``to_representation`` below many=True,