search changing newest to relevance on search now
This commit is contained in:
@@ -194,12 +194,17 @@ async fn run_search(
|
||||
items.retain(|i| view::category_filter_keep(&filter, i.product.category_id));
|
||||
|
||||
// 6. Sort. Newest-first is the default; relevance (the ranked search order)
|
||||
// is available explicitly via the sort control.
|
||||
let sort = params
|
||||
// is available explicitly via the sort control. When a search runs, the
|
||||
// default "newest" becomes "relevance" (a query implies relevance matters
|
||||
// most); any explicitly chosen non-newest sort is left untouched.
|
||||
let mut sort = params
|
||||
.sort
|
||||
.clone()
|
||||
.filter(|s| !s.is_empty())
|
||||
.unwrap_or_else(|| "newest".to_string());
|
||||
if !q_trim.is_empty() && sort == "newest" {
|
||||
sort = "relevance".to_string();
|
||||
}
|
||||
match sort.as_str() {
|
||||
"price_asc" => items.sort_by(|a, b| a.priced.price_cents.cmp(&b.priced.price_cents)),
|
||||
"price_desc" => items.sort_by(|a, b| b.priced.price_cents.cmp(&a.priced.price_cents)),
|
||||
@@ -391,6 +396,9 @@ async fn search(
|
||||
if fragment {
|
||||
if let Some(map) = context.as_object_mut() {
|
||||
map.insert("lang".into(), json!(lang));
|
||||
// Lets _results.html out-of-band swap the toolbar's Sort dropdown
|
||||
// (which lives outside the swapped region) to match the ordering.
|
||||
map.insert("is_fragment".into(), json!(true));
|
||||
}
|
||||
return format::view(&v, "shop/_results.html", context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user