Permalink
Browse files

add handles to exclude categories from search

  • Loading branch information...
hesslau committed Oct 18, 2018
1 parent 2ef89d6 commit 6ae6fd9d05c9583e148fe0c9f55957e49eff950c
@@ -296,3 +296,24 @@ a.Search-colored-link {
@include omega;
}
}
.Search-exclude-category,
.Search-include-category {
text-decoration:none;
&:hover {
text-decoration:none;
}
}
.Search-include-category {
opacity: 0.5;
&:hover {
opacity: 1;
}
}
.Search-exclude-category:before { content: ""; }
.Search-exclude-category:hover:before { content: "";}
.Search-include-category:before { content: "";}
.Search-include-category:hover:before { content: "";}
@@ -16,6 +16,7 @@ class ArticleSearchForm
attribute :condition, type: String
attribute :category_id, type: Integer
attribute :exclude_category_ids, type: Array
attribute :zip, type: String
attribute :order_by, type: String,
default_blank: true
@@ -45,6 +45,7 @@ def build
zip_filter,
price_filter,
category_filter,
exclude_categories_filter,
condition_filter,
category_aggregations,
sorting
@@ -133,6 +134,10 @@ def category_filter
index.filter(terms: { categories: [@query.category_id] }) if @query.category_id.present?
end
def exclude_categories_filter
index.filter.not( terms: {categories: @query.exclude_category_ids.map(&:to_i) }) if @query.exclude_category_ids.present?
end
# facets
def category_aggregations
index.aggregations(category: { terms: { field: :categories, size: 10000 } })
@@ -145,8 +150,13 @@ def isbn_normalizer
# sorting
def sorting
# try to get order key from query
order = @query.order_by
# if no order directive exists in query, order by relevance if we're searching for a specific term, otherwise order by newest
order = @query.search_by_term? ? 'relevance' : 'newest' unless order
# sort index
index.order(SORT[order])
end
end
@@ -10,7 +10,7 @@ def root
def default
[
:q, :fair, :ecologic, :small_and_precious, :condition,
:category_id, :zip, :order_by, :search_in_content
:category_id, :zip, :order_by, :search_in_content, :exclude_category_ids
]
end
end
@@ -2,14 +2,19 @@
- if local_assigns.has_key? :ignore_counts
- count = nil if ignore_counts
- displayed_name = category.name
- displayed_name += " (#{count})" if count
- if count != 0
- displayed_name += " (#{count})" if count.present? && count > 0
- excluded_category_ids = search_cache.exclude_category_ids || []
- if count != 0 or excluded_category_ids.map(&:to_i).include? category.id
li
span title=displayed_name
- if search_cache && search_cache.searched_category == category
b= displayed_name
- else
= link_to displayed_name, category_path(category, article_search_form: search_cache.change(category_id: category.id)), data: { push: true }
- if count == 0
= link_to " " + displayed_name, articles_path(article_search_form: search_cache.change(:exclude_category_ids => excluded_category_ids.reject{|k| k.to_i == category.id})), data: { push: true}, class: "Search-include-category"
- else
= link_to " ", articles_path(article_search_form: search_cache.change(:exclude_category_ids => excluded_category_ids + [category.id.to_s])), data: { push: true }, class: "Search-exclude-category"
= link_to displayed_name, category_path(category, article_search_form: search_cache.change(category_id: category.id)), data: { push: true }
- if local_assigns.has_key? :subtree
ul.Search-tree

0 comments on commit 6ae6fd9

Please sign in to comment.