Skip to content

Search: fix when searching an empty query #10312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions readthedocs/search/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ def test_search_no_owned_projects(self, client, all_projects):
)
assert len(results) == 0

def test_search_empty_query(self, client):
results, facets = self._get_search_result(
url=self.url,
client=client,
search_params={"q": "", "type": "project"},
)
assert results == []
assert facets == {}


@pytest.mark.django_db
@pytest.mark.search
Expand Down
5 changes: 3 additions & 2 deletions readthedocs/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ def _search_projects(self, user_input, request):
projects=projects,
use_advanced_query=True,
)
total_count = results.hits.total["value"]
results = ProjectSearchSerializer(results, many=True).data
if results:
total_count = results.hits.total["value"]
results = ProjectSearchSerializer(results, many=True).data
context = user_input._asdict()
context.update(
{
Expand Down