diff --git a/api/catalog/api/controllers/search_controller.py b/api/catalog/api/controllers/search_controller.py index e96585aee..626eb7c0a 100644 --- a/api/catalog/api/controllers/search_controller.py +++ b/api/catalog/api/controllers/search_controller.py @@ -239,7 +239,8 @@ def search( # names are identical. filters = [ ("extension", None), - ("categories", None), + ("category", None), + ("categories", "category"), ("aspect_ratio", None), ("size", None), ("source", None), diff --git a/api/catalog/api/serializers/audio_serializers.py b/api/catalog/api/serializers/audio_serializers.py index e1a6eea00..fcc5b60d1 100644 --- a/api/catalog/api/serializers/audio_serializers.py +++ b/api/catalog/api/serializers/audio_serializers.py @@ -52,7 +52,7 @@ class AudioSearchRequestSerializer( fields_names = [ *MediaSearchRequestSerializer.fields_names, *AudioSearchRequestSourceSerializer.field_names, - "categories", + "category", "duration", ] """ @@ -60,8 +60,8 @@ class AudioSearchRequestSerializer( used to generate Swagger documentation. """ - categories = serializers.CharField( - label="categories", + category = serializers.CharField( + label="category", help_text="A comma separated list of categories; available categories " "include `music`, `sound_effect`, `podcast`, `audiobook`, " "and `news`.", diff --git a/api/catalog/api/serializers/image_serializers.py b/api/catalog/api/serializers/image_serializers.py index 3def2a669..17dee58db 100644 --- a/api/catalog/api/serializers/image_serializers.py +++ b/api/catalog/api/serializers/image_serializers.py @@ -26,7 +26,7 @@ class ImageSearchRequestSerializer( fields_names = [ *MediaSearchRequestSerializer.fields_names, *ImageSearchRequestSourceSerializer.field_names, - "categories", + "category", "aspect_ratio", "size", ] @@ -36,8 +36,8 @@ class ImageSearchRequestSerializer( """ # Ref: ingestion_server/ingestion_server/categorize.py#Category - categories = serializers.CharField( - label="categories", + category = serializers.CharField( + label="category", help_text="A comma separated list of categories; available categories " "include `illustration`, `photograph`, and " "`digitized_artwork`.", diff --git a/api/test/audio_integration_test.py b/api/test/audio_integration_test.py index 72bf5f05c..f545cdb62 100644 --- a/api/test/audio_integration_test.py +++ b/api/test/audio_integration_test.py @@ -10,6 +10,7 @@ report, search, search_all_excluded, + search_by_category, search_consistency, search_quotes, search_source_and_excluded, @@ -34,6 +35,11 @@ def test_search(audio_fixture): search(audio_fixture) +def test_search_category_filtering(audio_fixture): + search_by_category("audio", "music", audio_fixture) + search_by_category("audio", "pronunciation", audio_fixture) + + def test_search_all_excluded(): search_all_excluded("audio", ["jamendo", "wikimedia_audio"]) diff --git a/api/test/media_integration.py b/api/test/media_integration.py index 51b858e11..9bc1c3409 100644 --- a/api/test/media_integration.py +++ b/api/test/media_integration.py @@ -14,6 +14,16 @@ def search(fixture): assert fixture["result_count"] > 0 +def search_by_category(media_path, category, fixture): + response = requests.get(f"{API_URL}/v1/{media_path}?category={category}") + assert response.status_code == 200 + data = json.loads(response.text) + assert data["result_count"] < fixture["result_count"] + results = data["results"] + # Make sure each result is from the specified category + assert all(audio_item["category"] == category for audio_item in results) + + def search_all_excluded(media_path, excluded_source): response = requests.get( f"{API_URL}/v1/{media_path}?q=test&excluded_source={','.join(excluded_source)}"