From c36b39707c35ff300444313e2fe224cfc9f3bf08 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Thu, 14 May 2020 15:49:54 -0500 Subject: [PATCH 1/2] Search: record queries with 0 results Now that we are saving the number of results, this is useful to see what content is missing from the docs. --- readthedocs/search/tasks.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/readthedocs/search/tasks.py b/readthedocs/search/tasks.py index c5432110c7e..cd82f8fe25e 100644 --- a/readthedocs/search/tasks.py +++ b/readthedocs/search/tasks.py @@ -171,16 +171,6 @@ def record_search_query(project_slug, version_slug, query, total_results, time_s partial_query.save() return - # don't record query with zero results. - if not total_results: - log.debug( - 'Not recording search query because of zero results. Passed arguments: ' - 'project_slug: %s, version_slug: %s, query: %s, total_results: %s, time: %s' % ( - project_slug, version_slug, query, total_results, time - ) - ) - return - project = Project.objects.filter(slug=project_slug).first() if not project: log.debug( From 1f8ad94b29f921858d3b730dd5c1338f935ce4b2 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Thu, 14 May 2020 16:16:20 -0500 Subject: [PATCH 2/2] Update tests --- readthedocs/search/tests/test_search_tasks.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/readthedocs/search/tests/test_search_tasks.py b/readthedocs/search/tests/test_search_tasks.py index 92501dfd367..8cc9c9cb757 100644 --- a/readthedocs/search/tests/test_search_tasks.py +++ b/readthedocs/search/tests/test_search_tasks.py @@ -87,8 +87,8 @@ def test_partial_queries_are_not_recorded(self, api_client): SearchQuery.objects.all().first().query == 'stack overflow' ), 'one SearchQuery should be there because partial queries gets updated' - def test_search_query_not_recorded_when_results_are_zero(self, api_client): - """Test that search queries are not recorded when they have zero results.""" + def test_search_query_recorded_when_results_are_zero(self, api_client): + """Test that search queries are recorded when they have zero results.""" assert ( SearchQuery.objects.all().count() == 0 @@ -102,10 +102,8 @@ def test_search_query_not_recorded_when_results_are_zero(self, api_client): } resp = api_client.get(self.url, search_params) - assert (resp.data['count'] == 0) - assert ( - SearchQuery.objects.all().count() == 0 - ), 'there should be 0 obj since there were no results.' + assert resp.data['count'] == 0 + assert SearchQuery.objects.all().count() == 1 def test_delete_old_search_queries_from_db(self, project): """Test that the old search queries are being deleted."""