faceted_search 3.5.3 → 3.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/app/models/faceted_search/facets.rb +5 -1
- data/app/models/faceted_search/facets/default.rb +8 -0
- data/app/models/faceted_search/facets/range.rb +24 -0
- data/app/models/faceted_search/facets/text.rb +2 -1
- data/app/views/faceted_search/_facets.html.erb +1 -1
- data/app/views/faceted_search/facets/range/_all.html.erb +25 -0
- data/app/views/faceted_search/facets/range/_selected.html.erb +7 -0
- data/app/views/faceted_search/facets/text/_all.html.erb +1 -2
- data/lib/faceted_search/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9c031c6042e6795df7c7465fba26d1ff6e8d8ad3c7f3db94859febdcf3df6e0
|
4
|
+
data.tar.gz: c534ffb91303aaa601e530bd2271bb36dcef60ec01d04ba97ee74645f8968e86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f062d6086f4608816429ad31f69cf706f7a7868e486183a3c42f7c1d546190c8142d8dcc6b2cb3fb91901b0f26f64cf49c848a3c5de37407d7cd9150ab0ca737
|
7
|
+
data.tar.gz: 90669a44d5ba16929296b22854a80446ddb88cde6ea2df4e38e96495e25ab61b3e7b38788fefce07ce78d5a55162bf11b9cef99106616f6bd9388da228f68b13
|
data/README.md
CHANGED
@@ -65,6 +65,15 @@ Create a model defining your facets:
|
|
65
65
|
Rails.application.routes.url_helpers.category_path(category_id)
|
66
66
|
}
|
67
67
|
}
|
68
|
+
|
69
|
+
# Filter with range input
|
70
|
+
filter_with_range :distance, {
|
71
|
+
min: 10,
|
72
|
+
max: 200,
|
73
|
+
step: 10,
|
74
|
+
default_value: 50,
|
75
|
+
hide_in_selected: true
|
76
|
+
}
|
68
77
|
end
|
69
78
|
end
|
70
79
|
|
@@ -39,7 +39,7 @@ module FacetedSearch
|
|
39
39
|
unless @results
|
40
40
|
scope = @model
|
41
41
|
list.each do |facet|
|
42
|
-
scope = facet.add_scope(scope)
|
42
|
+
scope = facet.add_scope(scope) unless facet.ignore_scope?
|
43
43
|
end
|
44
44
|
@results = scope.distinct
|
45
45
|
end
|
@@ -84,6 +84,10 @@ module FacetedSearch
|
|
84
84
|
add_facet FullTree, value, options
|
85
85
|
end
|
86
86
|
|
87
|
+
def filter_with_range(value, options = {})
|
88
|
+
add_facet Range, value, options
|
89
|
+
end
|
90
|
+
|
87
91
|
def params_for(value)
|
88
92
|
@params[value] if @params.has_key? value
|
89
93
|
end
|
@@ -25,6 +25,14 @@ module FacetedSearch
|
|
25
25
|
@options.has_key? :path_pattern
|
26
26
|
end
|
27
27
|
|
28
|
+
def ignore_scope?
|
29
|
+
@options[:ignore_scope] || false
|
30
|
+
end
|
31
|
+
|
32
|
+
def hide_in_selected?
|
33
|
+
@options[:hide_in_selected] || path_pattern?
|
34
|
+
end
|
35
|
+
|
28
36
|
def kind
|
29
37
|
self.class.to_s
|
30
38
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module FacetedSearch
|
2
|
+
class Facets::Range < Facets::Default
|
3
|
+
def min
|
4
|
+
@options[:min] || 0
|
5
|
+
end
|
6
|
+
|
7
|
+
def max
|
8
|
+
@options[:max] || 100
|
9
|
+
end
|
10
|
+
|
11
|
+
def step
|
12
|
+
@options[:step] || 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_value
|
16
|
+
@options[:default_value] || min
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_scope(scope)
|
20
|
+
return scope if params.blank?
|
21
|
+
scope.where("#{facets.model_table_name}.#{name}" => params)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module FacetedSearch
|
2
2
|
class Facets::Text < Facets::Default
|
3
|
+
include ActiveRecord::Sanitization
|
3
4
|
|
4
5
|
def placeholder
|
5
6
|
@options[:placeholder]
|
@@ -7,7 +8,7 @@ module FacetedSearch
|
|
7
8
|
|
8
9
|
def add_scope(scope)
|
9
10
|
return scope if params.blank?
|
10
|
-
scope.where("#{facets.model_table_name}.#{name} ILIKE ?", "%#{params}%")
|
11
|
+
scope.where("#{facets.model_table_name}.#{name} ILIKE ?", "%#{self.class.sanitize_sql_like(params)}%")
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -7,7 +7,7 @@ reset ||= 'Reset'
|
|
7
7
|
<ul class="faceted__facets-selected list-inline">
|
8
8
|
<% facets.list.each do |facet| %>
|
9
9
|
<%
|
10
|
-
next if facet.
|
10
|
+
next if facet.hide_in_selected?
|
11
11
|
partial = "#{facet.kind.underscore}/selected"
|
12
12
|
%>
|
13
13
|
<%= render partial, facet: facet %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<li>
|
2
|
+
<% unless facet.title.blank? %><b><%= facet.title %></b><% end %>
|
3
|
+
<%
|
4
|
+
value = params[:facets][facet.name] if params.dig(:facets, facet.name).present?
|
5
|
+
value ||= facet.default_value
|
6
|
+
%>
|
7
|
+
<form action="<%= anchor %>" class="faceted__facet__text form-inline">
|
8
|
+
<% facet.facets.list.each do |f| %>
|
9
|
+
<% next if f == facet || f.params.blank? || f.path_pattern? %>
|
10
|
+
<input type="hidden"
|
11
|
+
name="facets[<%= f.name %>]"
|
12
|
+
value="<%= f.params %>" />
|
13
|
+
<% end %>
|
14
|
+
<input type="range"
|
15
|
+
name="facets[<%= facet.name %>]"
|
16
|
+
min="<%= facet.min %>"
|
17
|
+
max="<%= facet.max %>"
|
18
|
+
step="<%= facet.step %>"
|
19
|
+
value="<%= value %>"
|
20
|
+
class="form-control-range" />
|
21
|
+
<input type="submit"
|
22
|
+
class="btn btn-light"
|
23
|
+
value="OK" />
|
24
|
+
</form>
|
25
|
+
</li>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<% value = params[:facets][facet.name] if params[:facets] && params[:facets].has_key?(facet.name) %>
|
2
|
+
<% unless value.blank? %>
|
3
|
+
<%= render 'faceted_search/facets/facet-selected',
|
4
|
+
title: facet.title,
|
5
|
+
value: value,
|
6
|
+
path: facet.facets.path_for(facet, nil) %>
|
7
|
+
<% end %>
|
@@ -3,8 +3,7 @@
|
|
3
3
|
<% value = params[:facets][facet.name] if params[:facets] && params[:facets].has_key?(facet.name) %>
|
4
4
|
<form action="<%= anchor %>" class="faceted__facet__text form-inline">
|
5
5
|
<% facet.facets.list.each do |f| %>
|
6
|
-
<% next if f == facet %>
|
7
|
-
<% next if f.params.blank? %>
|
6
|
+
<% next if f == facet || f.params.blank? || f.path_pattern? %>
|
8
7
|
<input type="hidden"
|
9
8
|
name="facets[<%= f.name %>]"
|
10
9
|
value="<%= f.params %>" />
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faceted_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.5.
|
4
|
+
version: 3.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Levy
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-05-
|
13
|
+
date: 2021-05-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- app/models/faceted_search/facets/full_tree.rb
|
138
138
|
- app/models/faceted_search/facets/list.rb
|
139
139
|
- app/models/faceted_search/facets/primitive_list.rb
|
140
|
+
- app/models/faceted_search/facets/range.rb
|
140
141
|
- app/models/faceted_search/facets/text.rb
|
141
142
|
- app/models/faceted_search/facets/tree.rb
|
142
143
|
- app/views/faceted_search/_facets.html.erb
|
@@ -154,6 +155,8 @@ files:
|
|
154
155
|
- app/views/faceted_search/facets/list/_selected.html.erb
|
155
156
|
- app/views/faceted_search/facets/primitive_list/_all.html.erb
|
156
157
|
- app/views/faceted_search/facets/primitive_list/_selected.html.erb
|
158
|
+
- app/views/faceted_search/facets/range/_all.html.erb
|
159
|
+
- app/views/faceted_search/facets/range/_selected.html.erb
|
157
160
|
- app/views/faceted_search/facets/text/_all.html.erb
|
158
161
|
- app/views/faceted_search/facets/text/_selected.html.erb
|
159
162
|
- app/views/faceted_search/facets/tree/_all.html.erb
|