Skip to content

Commit bb0b88c

Browse files
authored
Search: fix when searching an empty query (#10312)
Fixes #9969
1 parent 1e398ec commit bb0b88c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

readthedocs/search/tests/test_views.py

+9
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ def test_search_no_owned_projects(self, client, all_projects):
128128
)
129129
assert len(results) == 0
130130

131+
def test_search_empty_query(self, client):
132+
results, facets = self._get_search_result(
133+
url=self.url,
134+
client=client,
135+
search_params={"q": "", "type": "project"},
136+
)
137+
assert results == []
138+
assert facets == {}
139+
131140

132141
@pytest.mark.django_db
133142
@pytest.mark.search

readthedocs/search/views.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ def _search_projects(self, user_input, request):
136136
projects=projects,
137137
use_advanced_query=True,
138138
)
139-
total_count = results.hits.total["value"]
140-
results = ProjectSearchSerializer(results, many=True).data
139+
if results:
140+
total_count = results.hits.total["value"]
141+
results = ProjectSearchSerializer(results, many=True).data
141142
context = user_input._asdict()
142143
context.update(
143144
{

0 commit comments

Comments
 (0)