faceted_search 1.1.1 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -9
- data/app/models/faceted_search/facets/filter.rb +18 -1
- data/app/views/faceted_search/_facets.html.erb +3 -3
- data/app/views/faceted_search/facets/_filter.html.erb +4 -2
- data/app/views/faceted_search/facets/_search.html.erb +1 -1
- data/lib/faceted_search/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e88e213ff0887cfffb7ecc22d76fb060ddbedd2d037252e8e89695ec83928674
|
4
|
+
data.tar.gz: 74b00464aaa30ec6d50f301f9303027aff7c4754bd813f47e8aa2bf455751b05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a51c7a17c08a9bc49645803c2ae10b858497308e292532140430e9f1ed71800ff014f25d833a536029bcf3b75060147b9252c8d592feed00977917e8ffb52578
|
7
|
+
data.tar.gz: ef10c7dc53f665136d32eba99f6e04dd10ed88f3111d983fd93f2909c85602c2afcc739ae411820db3b5fc66a88e2bc8452b8242382239e0ee5d9904c5d7e4a3
|
data/README.md
CHANGED
@@ -26,12 +26,13 @@ $ gem install faceted_search
|
|
26
26
|
Create a model defining your facets:
|
27
27
|
|
28
28
|
class Item::Facets < FacetedSearch::Facets
|
29
|
-
def
|
30
|
-
|
29
|
+
def initialize(params)
|
30
|
+
super
|
31
|
+
@model = Item.all
|
31
32
|
search :title
|
32
|
-
filter :products, find_by: :title
|
33
|
-
filter :kinds
|
34
|
-
filter :categories
|
33
|
+
filter :products, find_by: :title, habtm: true
|
34
|
+
filter :kinds, habtm: true
|
35
|
+
filter :categories, habtm: true
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
@@ -60,9 +61,5 @@ In your view, do something like that (with bootstrap):
|
|
60
61
|
</div>
|
61
62
|
</div>
|
62
63
|
|
63
|
-
|
64
|
-
## Contributing
|
65
|
-
Contribution directions go here.
|
66
|
-
|
67
64
|
## License
|
68
65
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -12,19 +12,36 @@ module FacetedSearch
|
|
12
12
|
value.to_s.in? params_array
|
13
13
|
end
|
14
14
|
|
15
|
+
def results_with(value)
|
16
|
+
scope = @facets.model
|
17
|
+
@facets.list.each do |facet|
|
18
|
+
scope = facet == self ? add_scope_with_value(scope, value)
|
19
|
+
: facet.add_scope(scope)
|
20
|
+
end
|
21
|
+
scope
|
22
|
+
end
|
23
|
+
|
15
24
|
def params_array
|
16
25
|
@params_array ||= @params.to_s.split(',')
|
17
26
|
end
|
18
27
|
|
19
28
|
# Adds a scope corresponding to this facet
|
20
29
|
# to the scope sent as an argument
|
21
|
-
# and return the modified scope
|
30
|
+
# and return the modified scope
|
22
31
|
def add_scope(scope)
|
23
32
|
return scope if params_array.blank?
|
24
33
|
@habtm ? scope.joins(name).where(name => { find_by => params_array })
|
25
34
|
: scope.where(name => params_array)
|
26
35
|
end
|
27
36
|
|
37
|
+
# Adds a scope corresponding to this facet
|
38
|
+
# to the scope sent as an argument with specific value
|
39
|
+
# and return the modified scope
|
40
|
+
def add_scope_with_value(scope, value)
|
41
|
+
@habtm ? scope.joins(name).where(name => { find_by => value })
|
42
|
+
: scope.where(name => value)
|
43
|
+
end
|
44
|
+
|
28
45
|
# Show all values that have corresponding results.
|
29
46
|
# This is a regular SQL inner join.
|
30
47
|
def values
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<ul class="faceted__facets list-unstyled">
|
2
2
|
<% @facets.list.each do |facet| %>
|
3
|
-
<li
|
3
|
+
<li>
|
4
4
|
<b><%= facet.title %></b>
|
5
5
|
<%= render facet.kind.underscore, facet: facet %>
|
6
6
|
</li>
|
7
7
|
<% end %>
|
8
|
-
<li><a href="<%= @facets.path%>"><i class="fas fa-backspace"></i></a></li>
|
9
|
-
</ul>
|
8
|
+
<li class="faceted__facet__reinit"><a href="<%= @facets.path%>"><i class="fas fa-backspace"></i></a></li>
|
9
|
+
</ul>
|
@@ -1,12 +1,14 @@
|
|
1
|
-
<ul class="
|
1
|
+
<ul class="faceted__facet__filter list-unstyled">
|
2
2
|
<% facet.values.each do |value| %>
|
3
3
|
<%
|
4
4
|
identifier = value.send facet.find_by
|
5
5
|
selected = facet.selected? identifier
|
6
|
+
results_count = facet.results_with(value).count
|
7
|
+
next if results_count.zero?
|
6
8
|
%>
|
7
9
|
<li>
|
8
10
|
<% if selected %><b><% end %>
|
9
|
-
<%= link_to value, @facets.path_for(facet, identifier) %>
|
11
|
+
<%= link_to "#{value} (#{results_count})", @facets.path_for(facet, identifier) %>
|
10
12
|
<% if selected %></b><% end %>
|
11
13
|
</li>
|
12
14
|
<% end %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% value = params[:facets][facet.name] if params[:facets] && params[:facets].has_key?(facet.name) %>
|
2
|
-
<form action="" class="
|
2
|
+
<form action="" class="faceted__facet__search form-inline">
|
3
3
|
<% facet.facets.list.each do |f| %>
|
4
4
|
<% next if f == facet %>
|
5
5
|
<% next if f.params.blank? %>
|
metadata
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faceted_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Levy
|
8
|
+
- Sébastien Gaya
|
9
|
+
- Sébastien Moulène
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date: 2019-
|
13
|
+
date: 2019-03-13 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: rails
|
@@ -94,9 +96,11 @@ dependencies:
|
|
94
96
|
- - ">="
|
95
97
|
- !ruby/object:Gem::Version
|
96
98
|
version: '0'
|
97
|
-
description: All you need to create a faceted search, as
|
99
|
+
description: All you need to create a faceted search, as simple as possible
|
98
100
|
email:
|
99
101
|
- alevy@lespoupees.paris
|
102
|
+
- sebastien.gaya@gmail.com
|
103
|
+
- sebousan@gmail.com
|
100
104
|
executables: []
|
101
105
|
extensions: []
|
102
106
|
extra_rdoc_files: []
|