Remove score sorting constraint (#19501)

Do not require a score filter to be applied in order to sort by object score.
This commit is contained in:
Josh Hawkins 2025-08-16 08:08:11 -05:00 committed by GitHub
parent 2cde58037d
commit 89db960c05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 10 deletions

View File

@ -724,15 +724,24 @@ def events_search(request: Request, params: EventsSearchQueryParams = Depends())
if (sort is None or sort == "relevance") and search_results:
processed_events.sort(key=lambda x: x.get("search_distance", float("inf")))
elif min_score is not None and max_score is not None and sort == "score_asc":
elif sort == "score_asc":
processed_events.sort(key=lambda x: x["data"]["score"])
elif min_score is not None and max_score is not None and sort == "score_desc":
elif sort == "score_desc":
processed_events.sort(key=lambda x: x["data"]["score"], reverse=True)
elif min_speed is not None and max_speed is not None and sort == "speed_asc":
processed_events.sort(key=lambda x: x["data"]["average_estimated_speed"])
elif min_speed is not None and max_speed is not None and sort == "speed_desc":
elif sort == "speed_asc":
processed_events.sort(
key=lambda x: x["data"]["average_estimated_speed"], reverse=True
key=lambda x: (
x["data"].get("average_estimated_speed") is None,
x["data"].get("average_estimated_speed"),
)
)
elif sort == "speed_desc":
processed_events.sort(
key=lambda x: (
x["data"].get("average_estimated_speed") is None,
x["data"].get("average_estimated_speed", float("-inf")),
),
reverse=True,
)
elif sort == "date_asc":
processed_events.sort(key=lambda x: x["start_time"])

View File

@ -131,10 +131,7 @@ export default function SearchFilterGroup({
);
const availableSortTypes = useMemo(() => {
const sortTypes = ["date_asc", "date_desc"];
if (filter?.min_score || filter?.max_score) {
sortTypes.push("score_desc", "score_asc");
}
const sortTypes = ["date_asc", "date_desc", "score_desc", "score_asc"];
if (filter?.min_speed || filter?.max_speed) {
sortTypes.push("speed_desc", "speed_asc");
}