defaults for the search implemented
This commit is contained in:
@@ -57,7 +57,7 @@
|
|||||||
{{ t(key="sort-label", lang=L) }}
|
{{ t(key="sort-label", lang=L) }}
|
||||||
<select name="sort"
|
<select name="sort"
|
||||||
class="rounded-radius border border-outline bg-surface px-2 py-1.5 text-sm text-on-surface focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary dark:border-outline-dark dark:bg-surface-dark dark:text-on-surface-dark">
|
class="rounded-radius border border-outline bg-surface px-2 py-1.5 text-sm text-on-surface focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary dark:border-outline-dark dark:bg-surface-dark dark:text-on-surface-dark">
|
||||||
{% for opt in ["relevance", "newest", "price_asc", "price_desc", "name_asc", "name_desc"] %}
|
{% for opt in ["newest", "relevance", "price_asc", "price_desc", "name_asc", "name_desc"] %}
|
||||||
<option value="{{ opt }}"{% if sort == opt %} selected{% endif %}>{{ t(key="sort-" ~ opt, lang=L) }}</option>
|
<option value="{{ opt }}"{% if sort == opt %} selected{% endif %}>{{ t(key="sort-" ~ opt, lang=L) }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -164,13 +164,13 @@ async fn run_search(
|
|||||||
let filter = view::category_filter_ids(&all_categories, &selected_category);
|
let filter = view::category_filter_ids(&all_categories, &selected_category);
|
||||||
items.retain(|i| view::category_filter_keep(&filter, i.product.category_id));
|
items.retain(|i| view::category_filter_keep(&filter, i.product.category_id));
|
||||||
|
|
||||||
// 6. Sort. Relevance is the default; with no text query it keeps the base
|
// 6. Sort. Newest-first is the default; relevance (the ranked search order)
|
||||||
// order (newest-first), and with a query it keeps the ranked search order.
|
// is available explicitly via the sort control.
|
||||||
let sort = params
|
let sort = params
|
||||||
.sort
|
.sort
|
||||||
.clone()
|
.clone()
|
||||||
.filter(|s| !s.is_empty())
|
.filter(|s| !s.is_empty())
|
||||||
.unwrap_or_else(|| "relevance".to_string());
|
.unwrap_or_else(|| "newest".to_string());
|
||||||
match sort.as_str() {
|
match sort.as_str() {
|
||||||
"price_asc" => items.sort_by(|a, b| a.priced.price_cents.cmp(&b.priced.price_cents)),
|
"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)),
|
"price_desc" => items.sort_by(|a, b| b.priced.price_cents.cmp(&a.priced.price_cents)),
|
||||||
|
|||||||
Reference in New Issue
Block a user