Skip to content

Commit 9e7be2b

Browse files
authored
Merge pull request #7081 from readthedocs/record-all-queries
Search: record queries with 0 results
2 parents 7bd678e + 1f8ad94 commit 9e7be2b

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

readthedocs/search/tasks.py

-10
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,6 @@ def record_search_query(project_slug, version_slug, query, total_results, time_s
171171
partial_query.save()
172172
return
173173

174-
# don't record query with zero results.
175-
if not total_results:
176-
log.debug(
177-
'Not recording search query because of zero results. Passed arguments: '
178-
'project_slug: %s, version_slug: %s, query: %s, total_results: %s, time: %s' % (
179-
project_slug, version_slug, query, total_results, time
180-
)
181-
)
182-
return
183-
184174
project = Project.objects.filter(slug=project_slug).first()
185175
if not project:
186176
log.debug(

readthedocs/search/tests/test_search_tasks.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def test_partial_queries_are_not_recorded(self, api_client):
8787
SearchQuery.objects.all().first().query == 'stack overflow'
8888
), 'one SearchQuery should be there because partial queries gets updated'
8989

90-
def test_search_query_not_recorded_when_results_are_zero(self, api_client):
91-
"""Test that search queries are not recorded when they have zero results."""
90+
def test_search_query_recorded_when_results_are_zero(self, api_client):
91+
"""Test that search queries are recorded when they have zero results."""
9292

9393
assert (
9494
SearchQuery.objects.all().count() == 0
@@ -102,10 +102,8 @@ def test_search_query_not_recorded_when_results_are_zero(self, api_client):
102102
}
103103
resp = api_client.get(self.url, search_params)
104104

105-
assert (resp.data['count'] == 0)
106-
assert (
107-
SearchQuery.objects.all().count() == 0
108-
), 'there should be 0 obj since there were no results.'
105+
assert resp.data['count'] == 0
106+
assert SearchQuery.objects.all().count() == 1
109107

110108
def test_delete_old_search_queries_from_db(self, project):
111109
"""Test that the old search queries are being deleted."""

0 commit comments

Comments
 (0)