Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Remove qa param from api (#2322)
Ashir Amin35100d3c719e
diff --git a/api/api/serializers/media_serializers.py b/api/api/serializers/media_serializers.pyindex 1149cbd3c..a0a90c8e7 100644--- a/api/api/serializers/media_serializers.py+++ b/api/api/serializers/media_serializers.py@@ -58,7 +58,6 @@ class MediaSearchRequestSerializer(serializers.Serializer):"filter_dead","extension","mature",- "qa",# Excluded unstable fields, also see `exclude_fields` above.# "unstable__sort_by",# "unstable__sort_dir",@@ -125,13 +124,6 @@ class MediaSearchRequestSerializer(serializers.Serializer):required=False,help_text="Whether to include content for mature audiences.",)- qa = serializers.BooleanField(- label="quality_assurance",- help_text="If enabled, searches are performed against the quality"- " assurance index instead of production.",- required=False,- default=False,- )# The ``unstable__`` prefix is used in the query params.# The validated data does not contain the ``unstable__`` prefix.@@ -335,11 +327,6 @@ class MediaSearchRequestSerializer(serializers.Serializer):if errors:raise serializers.ValidationError(errors)- if "qa" in self.initial_data and "internal__index" in self.initial_data:- raise serializers.ValidationError(- "Cannot set both 'qa' and 'internal__index'. "- "Use exactly one of these."- )return data@propertydiff --git a/api/api/views/audio_views.py b/api/api/views/audio_views.pyindex 7d50e78ce..c26fe8055 100644--- a/api/api/views/audio_views.py+++ b/api/api/views/audio_views.py@@ -40,7 +40,6 @@ class AudioViewSet(MediaViewSet):model_class = Audioquery_serializer_class = AudioSearchRequestSerializerdefault_index = settings.MEDIA_INDEX_MAPPING[AUDIO_TYPE]- qa_index = "search-qa-audio"serializer_class = AudioSerializerdiff --git a/api/api/views/image_views.py b/api/api/views/image_views.pyindex 030c74a08..95844ffbf 100644--- a/api/api/views/image_views.py+++ b/api/api/views/image_views.py@@ -50,7 +50,6 @@ class ImageViewSet(MediaViewSet):model_class = Imagequery_serializer_class = ImageSearchRequestSerializerdefault_index = settings.MEDIA_INDEX_MAPPING[IMAGE_TYPE]- qa_index = "search-qa-image"serializer_class = ImageSerializerdiff --git a/api/api/views/media_views.py b/api/api/views/media_views.pyindex 1bdba95e2..6a6d69fea 100644--- a/api/api/views/media_views.py+++ b/api/api/views/media_views.py@@ -29,7 +29,6 @@ class MediaViewSet(ReadOnlyModelViewSet):model_class = Nonequery_serializer_class = Nonedefault_index = None- qa_index = Nonedef __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)@@ -37,7 +36,6 @@ class MediaViewSet(ReadOnlyModelViewSet):self.model_class,self.query_serializer_class,self.default_index,- self.qa_index,]if any(val is None for val in required_fields):msg = "Viewset fields are not completely populated."@@ -82,14 +80,9 @@ class MediaViewSet(ReadOnlyModelViewSet):page = self.paginator.page = params.data["page"]hashed_ip = hash(self._get_user_ip(request))- qa = params.validated_data["qa"]filter_dead = params.validated_data["filter_dead"]- if qa:- logger.info("Using QA index for media.")- search_index = self.qa_index- exact_index = False- elif pref_index := params.validated_data.get("index"):+ if pref_index := params.validated_data.get("index"):logger.info(f"Using preferred index {pref_index} for media.")search_index = pref_indexexact_index = Truediff --git a/api/test/search_qa.py b/api/test/search_qa.pydeleted file mode 100644index 32416578c..000000000--- a/api/test/search_qa.py+++ /dev/null@@ -1,26 +0,0 @@-"""Perform some basic tests to ensure that search rankings work as anticipated."""--import json-import pprint-from enum import Enum--import pytest-import requests--from .api_live_integration import API_URL---class QAScores(Enum):- TARGET = 1- LESS_RELEVANT = 2- NOT_RELEVANT = 3--[email protected](reason="This test is nondeterministic")-def test_phrase_relevance():- res = requests.get(f"{API_URL}/image/search?q=home office&qa=true")- parsed = json.loads(res.text)- pprint.pprint(parsed)- assert int(parsed["results"][0]["id"]) == QAScores.TARGET.value- assert int(parsed["results"][1]["id"]) < QAScores.NOT_RELEVANT.value- assert int(parsed["results"][-1]["id"]) != QAScores.NOT_RELEVANT.valuediff --git a/api/test/unit/serializers/test_media_serializers.py b/api/test/unit/serializers/test_media_serializers.pyindex d8b73f332..9aea4c65f 100644--- a/api/test/unit/serializers/test_media_serializers.py+++ b/api/test/unit/serializers/test_media_serializers.py@@ -180,30 +180,6 @@ def test_search_request_serializer_include_sensitive_results_malformed_request(dassert not serializer.is_valid()-@patch("django.conf.settings.ES")- "data",- (- {"qa": True, "internal__index": "some-index"},- {"qa": False, "internal__index": "some-index"},- ),-)-def test_search_request_serializer_fails_contradictory_params(- mock_es, data, authed_request-):- mock_es.indices.exists.return_value = True-- serializer = MediaSearchRequestSerializer(- data=data, context={"request": authed_request}- )- assert not serializer.is_valid()- assert (- "Cannot set both 'qa' and 'internal__index'."- in serializer.errors["non_field_errors"][0]- )--@pytest.mark.django_db@patch("django.conf.settings.ES")@pytest.mark.parametrize(diff --git a/ingestion_server/ingestion_server/indexer.py b/ingestion_server/ingestion_server/indexer.pyindex 33e613690..c8e149c40 100644--- a/ingestion_server/ingestion_server/indexer.py+++ b/ingestion_server/ingestion_server/indexer.py@@ -36,7 +36,6 @@ from ingestion_server.distributed_reindex_scheduler import schedule_distributed_from ingestion_server.elasticsearch_models import media_type_to_elasticsearch_modelfrom ingestion_server.es_helpers import get_statfrom ingestion_server.es_mapping import index_settings-from ingestion_server.qa import create_search_qa_indexfrom ingestion_server.queries import get_existence_queriesfrom ingestion_server.utils.sensitive_terms import get_sensitive_terms@@ -338,17 +337,6 @@ class TableIndexer:self.refresh(destination_index)self.ping_callback()- def load_test_data(self, model_name: str, **_):- """- Create test indices in Elasticsearch for QA.-- :param model_name: the name of the media type- """-- create_search_qa_index(model_name)- if self.progress is not None:- self.progress.value = 100 # mark job as completed-def point_alias(self, model_name: str, index_suffix: str, alias: str, **_):"""Map the given index to the given alias.diff --git a/ingestion_server/ingestion_server/qa.py b/ingestion_server/ingestion_server/qa.pydeleted file mode 100644index d24c289d1..000000000--- a/ingestion_server/ingestion_server/qa.py+++ /dev/null@@ -1,127 +0,0 @@-import random-from enum import Enum--from ingestion_server.elasticsearch_models import Audio, Image---class QAScores(Enum):- TARGET = 1- LESS_RELEVANT = 2- NOT_RELEVANT = 3---def create_search_qa_index(table):- # This changes search-qa for images to search-qa-image- test_idx = f"search-qa-{table}"- if table == "image":- _phrase_relevance_images(test_idx)- elif table == "audio":- _phrase_relevance_audio(test_idx)---def _test_doc_attrs(title, tags, creator, relevance):- _id = random.randint(0, 1000000000)- sample_url = "https://example.com/"- return {- "_id": _id,- "id": _id,- "title": title,- "identifier": relevance,- "creator": creator,- "creator_url": sample_url,- "tags": tags,- "created_on": None,- "url": sample_url,- "thumbnail": "",- "provider": "test",- "source": sample_url,- "license": "by",- "license_version": "3.0",- "foreign_landing_url": sample_url,- "metadata": None,- "view_count": 0,- }---def _test_image(title, tags, creator, relevance):- img = Image(**_test_doc_attrs(title, tags, creator, relevance))- return img---def _test_audio(title, tags, creator, relevance):- aud = Audio(**_test_doc_attrs(title, tags, creator, relevance))- return aud---def _phrase_relevance_images(index):- """Create documents for images with varying relevance in the given index."""-- less_relevant_1 = _test_image(- title="A picture of my office",- tags=[{"name": "office"}],- creator="Alice Foo",- relevance=QAScores.LESS_RELEVANT.value,- )- less_relevant_1.save(index=index)-- less_relevant_2 = _test_image(- title="My office in my home",- tags=[{"name": "office"}, {"name": "home"}],- creator="Gordon",- relevance=QAScores.LESS_RELEVANT.value,- )- less_relevant_2.save(index=index)-- not_relevant = _test_image(- title="Mastiff",- tags=[{"name": "dog"}],- creator="Liam",- relevance=QAScores.NOT_RELEVANT.value,- )- not_relevant.save(index=index)-- # This should be the top result.- target = _test_image(- title="My home office",- tags=[{"name": "home office"}, {"name": "noise"}, {"name": "clutter"}],- creator="John Fooson",- relevance=QAScores.TARGET.value,- )- target.save(index=index)---def _phrase_relevance_audio(index):- """Create documents for audio with varying relevance in the given index."""-- less_relevant_1 = _test_audio(- title="Symphony No. 1 in C major, Op. 21",- tags=[{"name": "symphony"}, {"name": "c.major"}],- creator="Ludvig van Beethoven",- relevance=QAScores.LESS_RELEVANT.value,- )- less_relevant_1.save(index=index)-- less_relevant_2 = _test_audio(- title="Symphony No. 9 in C major, D 944",- tags=[{"name": "symphony"}, {"name": "c.major"}],- creator="Franz Schubert",- relevance=QAScores.LESS_RELEVANT.value,- )- less_relevant_2.save(index=index)-- not_relevant = _test_audio(- title="Serenade No. 13 for strings in G major, K. 525",- tags=[{"name": "serenade"}, {"name": "g.major"}],- creator="Wolfgang Amadeus Mozart",- relevance=QAScores.NOT_RELEVANT.value,- )- not_relevant.save(index=index)-- # This should be the top result.- target = _test_audio(- title="Symphony No. 5 in C minor, Op. 67",- tags=[{"name": "symphony"}, {"name": "c.minor"}],- creator="Ludwig van Beethoven",- relevance=QAScores.TARGET.value,- )- target.save(index=index)