faceted_search 3.5.1 → 3.5.6
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 +14 -8
- data/app/models/faceted_search/facets/date.rb +6 -6
- data/app/models/faceted_search/facets/default.rb +8 -0
- data/app/models/faceted_search/facets/default_list.rb +3 -3
- data/app/models/faceted_search/facets/primitive_list.rb +8 -4
- 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 +5 -2
- data/app/views/faceted_search/facets/checkboxes/_selected.html.erb +1 -1
- data/app/views/faceted_search/facets/date/_selected.html.erb +1 -1
- data/app/views/faceted_search/facets/full_tree/_all.html.erb +1 -1
- data/app/views/faceted_search/facets/full_tree/_selected.html.erb +2 -1
- data/app/views/faceted_search/facets/full_tree/_values-selected.html.erb +1 -1
- data/app/views/faceted_search/facets/full_tree/_values.html.erb +2 -2
- data/app/views/faceted_search/facets/list/_selected.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/app/views/faceted_search/facets/text/_selected.html.erb +1 -1
- data/app/views/faceted_search/facets/tree/_all.html.erb +2 -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: 109687180e0ee8bc369a74c9884430021f167fd43694b7ee43a4cdd486846af6
|
4
|
+
data.tar.gz: ec7bd149ecbdb47adb470f7b88da290f59247544034de5fb1184104426c95aac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a1cd9a1f7ad2ce69a778b7cef0c826ad97b277b6700f5973e5a7479c23c9a35d11fd64938bf1b21a389233520c84b974478ac33ae3c2a52cb5287fdde35dc0b
|
7
|
+
data.tar.gz: 7a9f15c607f02534ea00ddd6ad59122af8a765ba7cf4aa16459bfe207b6d07ab982250f3a0d23ebf1d3a765073b150a4aa2d26b2530cf3d4ed0206683d7060f1
|
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
|
|
@@ -27,23 +27,25 @@ module FacetedSearch
|
|
27
27
|
else
|
28
28
|
p = path
|
29
29
|
list.each do |current_facet|
|
30
|
+
next if current_facet.path_pattern?
|
30
31
|
p += current_facet == facet ? current_facet.path_for(value)
|
31
32
|
: current_facet.path
|
32
33
|
end
|
33
34
|
end
|
34
|
-
p.delete_suffix!(path) if p.end_with?(path)
|
35
35
|
p
|
36
36
|
end
|
37
37
|
|
38
38
|
def results
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
@results ||= results_except []
|
40
|
+
end
|
41
|
+
|
42
|
+
def results_except(*facet_names)
|
43
|
+
scope = @model
|
44
|
+
list.each do |facet|
|
45
|
+
next if facet_names.include?(facet.name) || facet.ignore_scope?
|
46
|
+
scope = facet.add_scope(scope)
|
45
47
|
end
|
46
|
-
|
48
|
+
scope.distinct
|
47
49
|
end
|
48
50
|
|
49
51
|
def model_table_name
|
@@ -84,6 +86,10 @@ module FacetedSearch
|
|
84
86
|
add_facet FullTree, value, options
|
85
87
|
end
|
86
88
|
|
89
|
+
def filter_with_range(value, options = {})
|
90
|
+
add_facet Range, value, options
|
91
|
+
end
|
92
|
+
|
87
93
|
def params_for(value)
|
88
94
|
@params[value] if @params.has_key? value
|
89
95
|
end
|
@@ -2,7 +2,11 @@ module FacetedSearch
|
|
2
2
|
class Facets::Date < Facets::DefaultList
|
3
3
|
|
4
4
|
def source
|
5
|
-
@
|
5
|
+
@source ||= begin
|
6
|
+
next @options[:source] if @options[:source].present?
|
7
|
+
results = params_array.blank? ? facets.results : facets.results_except(@name)
|
8
|
+
results.send(:all).pluck(name).compact.map(&:year).uniq.sort
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
12
|
def order
|
@@ -19,11 +23,7 @@ module FacetedSearch
|
|
19
23
|
end
|
20
24
|
|
21
25
|
def values
|
22
|
-
|
23
|
-
@values = source
|
24
|
-
@values.reverse! unless order == :asc
|
25
|
-
end
|
26
|
-
@values
|
26
|
+
@values ||= order == :asc ? source : source.reverse
|
27
27
|
end
|
28
28
|
end
|
29
29
|
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
|
@@ -26,11 +26,11 @@ module FacetedSearch
|
|
26
26
|
# Show all values that have corresponding results with the current params.
|
27
27
|
# This is a regular SQL inner join.
|
28
28
|
def values
|
29
|
-
|
29
|
+
@values ||= begin
|
30
30
|
joined_table = facets.model_table_name.to_sym
|
31
|
-
|
31
|
+
results = params_array.blank? ? facets.results : facets.results_except(@name)
|
32
|
+
source.all.joins(joined_table).where(joined_table => { id: results }).distinct
|
32
33
|
end
|
33
|
-
@values
|
34
34
|
end
|
35
35
|
|
36
36
|
def value_selected?(value)
|
@@ -2,6 +2,11 @@ module FacetedSearch
|
|
2
2
|
class Facets::PrimitiveList < Facets::DefaultList
|
3
3
|
|
4
4
|
def source
|
5
|
+
@source ||= begin
|
6
|
+
next @options[:source] if @options[:source].present?
|
7
|
+
results = params_array.compact.blank? ? facets.results : facets.results_except(@name)
|
8
|
+
results.send(:all).where("#{field} IS NOT NULL")
|
9
|
+
end
|
5
10
|
@options[:source].where("#{field} IS NOT NULL")
|
6
11
|
end
|
7
12
|
|
@@ -22,11 +27,10 @@ module FacetedSearch
|
|
22
27
|
end
|
23
28
|
|
24
29
|
def values
|
25
|
-
|
26
|
-
|
27
|
-
|
30
|
+
@values ||= begin
|
31
|
+
values = source.pluck(field).uniq.reject(&:blank?).sort
|
32
|
+
order == :asc ? values : values.reverse
|
28
33
|
end
|
29
|
-
@values
|
30
34
|
end
|
31
35
|
end
|
32
36
|
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
|
@@ -6,8 +6,11 @@ reset ||= 'Reset'
|
|
6
6
|
<% if facets.has_params? %>
|
7
7
|
<ul class="faceted__facets-selected list-inline">
|
8
8
|
<% facets.list.each do |facet| %>
|
9
|
-
<%
|
10
|
-
|
9
|
+
<%
|
10
|
+
next if facet.hide_in_selected?
|
11
|
+
partial = "#{facet.kind.underscore}/selected"
|
12
|
+
%>
|
13
|
+
<%= render partial, facet: facet, anchor: anchor %>
|
11
14
|
<% end %>
|
12
15
|
</ul>
|
13
16
|
<% end %>
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<div class="static-nestable-list">
|
5
5
|
<div class="dd">
|
6
6
|
<ol class="faceted__facet__full_tree list-unstyled dd-list">
|
7
|
-
<%= render 'faceted_search/facets/full_tree/values', values: facet.values_with_parent(nil), facet: facet %>
|
7
|
+
<%= render 'faceted_search/facets/full_tree/values', values: facet.values_with_parent(nil), facet: facet, anchor: anchor %>
|
8
8
|
</ol>
|
9
9
|
</div>
|
10
10
|
</div>
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<%= render 'faceted_search/facets/facet-selected',
|
5
5
|
title: facet.title,
|
6
6
|
value: facet.display_method.call(value),
|
7
|
-
path: facet.facets.path_for(facet, identifier) %>
|
7
|
+
path: facet.facets.path_for(facet, identifier) + anchor %>
|
8
8
|
<% end %>
|
9
9
|
<% child_values = facet.values_with_parent(value.id) %>
|
10
10
|
<% if child_values.any? %>
|
@@ -3,12 +3,12 @@
|
|
3
3
|
<li class="faceted__facet__full_tree__value<%= '--selected' if facet.value_selected?(identifier) %> dd-item <%= 'dd-item--selected' if facet.value_selected?(identifier) %>">
|
4
4
|
<%= render 'faceted_search/link',
|
5
5
|
display_value: facet.display_method.call(value),
|
6
|
-
path: facet.facets.path_for(facet, identifier),
|
6
|
+
path: facet.facets.path_for(facet, identifier) + anchor,
|
7
7
|
searchable: facet.searchable %>
|
8
8
|
<% child_values = facet.values_with_parent(value.id) %>
|
9
9
|
<% if child_values.any? %>
|
10
10
|
<ol class="dd-list">
|
11
|
-
<%= render 'faceted_search/facets/full_tree/values', values: child_values, facet: facet %>
|
11
|
+
<%= render 'faceted_search/facets/full_tree/values', values: child_values, facet: facet, anchor: anchor %>
|
12
12
|
</ol>
|
13
13
|
<% end %>
|
14
14
|
</li>
|
@@ -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) + anchor %>
|
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 %>" />
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<%
|
7
7
|
display_value = facet.display_method.call(facet.selected_object)
|
8
8
|
identifier = facet.selected_object.send facet.find_by
|
9
|
-
path = facet.facets.path_for(facet, identifier)
|
9
|
+
path = facet.facets.path_for(facet, identifier) + anchor
|
10
10
|
%>
|
11
11
|
<div class="faceted__facet__tree__back">
|
12
12
|
<%= link_to path, rel: 'nofollow' do %>
|
@@ -20,7 +20,7 @@
|
|
20
20
|
<%
|
21
21
|
display_value = facet.display_method.call(value)
|
22
22
|
identifier = value.send facet.find_by
|
23
|
-
path = facet.facets.path_for(facet, identifier)
|
23
|
+
path = facet.facets.path_for(facet, identifier) + anchor
|
24
24
|
%>
|
25
25
|
<li class="faceted__facet__tree__value">
|
26
26
|
<%= render 'faceted_search/link',
|
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.6
|
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
|