Skip to content
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

feat: sort non keyword search results a-z #854

Merged
merged 1 commit into from
Sep 19, 2024
Merged
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
14 changes: 11 additions & 3 deletions home/service/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ def _format_query_value(self, query: str) -> str:
def _get_search_results(self, page: str, items_per_page: int) -> SearchResponse:
form_data = self.form_data
query = self._format_query_value(form_data.get("query", ""))
sort = form_data.get("sort", "relevance")

# we want to sort results ascending when a user is browsing data via non
# keyword searches - otherwise we use the default releveant ordering
sort = (
form_data.get("sort", "relevance")
if query not in ["*", ""]
else "ascending"
)

domain = form_data.get("domain", "")
tags = form_data.get("tags", "")
where_to_access = self._build_custom_property_filter(
Expand All @@ -86,9 +94,9 @@ def _get_search_results(self, page: str, items_per_page: int) -> SearchResponse:

page_for_search = str(int(page) - 1)
if sort == "ascending":
sort_option = SortOption(field="name", ascending=True)
sort_option = SortOption(field="_entityName", ascending=True)
elif sort == "descending":
sort_option = SortOption(field="name", ascending=False)
sort_option = SortOption(field="_entityName", ascending=False)
else:
sort_option = None

Expand Down