Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add duration and category to ES mappings (#291)

sarayourfriend80d3358ab35a
diff --git a/ingestion_server/ingestion_server/elasticsearch_models.py b/ingestion_server/ingestion_server/elasticsearch_models.py
index 2922709ee..1be9cf51a 100644
--- a/ingestion_server/ingestion_server/elasticsearch_models.py
+++ b/ingestion_server/ingestion_server/elasticsearch_models.py
@@ -324,6 +324,7 @@ class Audio(Media):
sample_rate=row[schema["sample_rate"]],
genres=row[schema["genres"]],
category=row[schema["category"]],
+ duration=row[schema["duration"]],
authority_boost=authority_boost,
max_boost=max(popularity or 1, authority_boost or 1),
min_boost=min(popularity or 1, authority_boost or 1),
diff --git a/ingestion_server/ingestion_server/es_mapping.py b/ingestion_server/ingestion_server/es_mapping.py
index 8a33ccdfa..385097946 100644
--- a/ingestion_server/ingestion_server/es_mapping.py
+++ b/ingestion_server/ingestion_server/es_mapping.py
@@ -135,6 +135,8 @@ def index_settings(table_name):
"bit_rate": {"type": "integer"},
"sample_rate": {"type": "integer"},
"genres": {"fields": {"keyword": {"type": "keyword"}}, "type": "text"},
+ "duration": {"type": "integer"},
+ "category": {"type": "keyword"},
},
}
media_mappings = common_mappings.copy()
diff --git a/openverse_api/catalog/api/examples/audio_responses.py b/openverse_api/catalog/api/examples/audio_responses.py
index dffe5e197..565e4fee2 100644
--- a/openverse_api/catalog/api/examples/audio_responses.py
+++ b/openverse_api/catalog/api/examples/audio_responses.py
@@ -34,6 +34,8 @@ base_audio = {
"waveform": f"{origin}/v1/audio/{identifier}/waveform/",
"detail_url": f"{origin}/v1/audio/{identifier}/",
"related_url": f"{origin}/v1/audio/{identifier}/related/",
+ "category": "{music}",
+ "duration": 270000,
}
audio_search_200_example = {
diff --git a/openverse_api/catalog/api/serializers/audio_serializers.py b/openverse_api/catalog/api/serializers/audio_serializers.py
index e15eba6b9..5f75fa199 100644
--- a/openverse_api/catalog/api/serializers/audio_serializers.py
+++ b/openverse_api/catalog/api/serializers/audio_serializers.py
@@ -85,6 +85,7 @@ class AudioSerializer(MediaSerializer):
"alt_files",
"detail_url",
"related_url",
+ "category",
]
"""
Keep the fields names in sync with the actual fields below as this list is
@@ -119,6 +120,10 @@ class AudioSerializer(MediaSerializer):
required=False, help_text="JSON describing alternative files for this audio."
)
+ category = serializers.CharField(
+ required=False, help_text="The category of the audio."
+ )
+
# Hyperlinks
thumbnail = serializers.HyperlinkedIdentityField(
read_only=True,