faceted_search 3.5.3 → 3.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '04106970c4095477714e7d1a968b62ed26b5d0bd155995c1bb90570fab2e7534'
4
- data.tar.gz: 23d62e43c40553664cc941f8e5ec80090c5a7e5a39be72e5c06368427ff1c1cb
3
+ metadata.gz: 265734657b1546de2a80bb631adf099b8758bedd7baf5f4af71a3c266cbf2547
4
+ data.tar.gz: 66f75f2e72f13bb7bb67b94d613c4597a866e8cba1c1f2dc789cbae542f851a8
5
5
  SHA512:
6
- metadata.gz: cfd6cd87a2b7ba8be6ed284337169a9ea487aba35d5f0ffdbf3b0d662c78b0d05aa611b11e75ee9171030929a63fa4fd1a60e24f7e044ee25c8fb37b5bf2bff1
7
- data.tar.gz: a32ca6d1a6c37bd1b84b246b824415bcae8ec712878606f77f115de4a55cf40341afca91273ba2b5c4e1c269114688a1d61e300b85853017c0ef31030012c1f8
6
+ metadata.gz: de25113088db0880b13fa1aef84d86b03fe88572e54f334c7b2c7bcff4e6831a87d253c1cbb14f9483167ca5edc2ad041e34dbb8773aff732fd080ddc56fff58
7
+ data.tar.gz: e687d54f22dbb7d1b00a897268b07bb5a51de83a7980dbb1f190df105c381733f1f907031490b9da6cf3bd004867f45b9cc70dd42efb3c59cf251e084838b22d
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
 
@@ -36,14 +36,16 @@ module FacetedSearch
36
36
  end
37
37
 
38
38
  def results
39
- unless @results
40
- scope = @model
41
- list.each do |facet|
42
- scope = facet.add_scope(scope)
43
- end
44
- @results = scope.distinct
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
- @results
48
+ scope.distinct
47
49
  end
48
50
 
49
51
  def model_table_name
@@ -51,7 +53,12 @@ module FacetedSearch
51
53
  end
52
54
 
53
55
  def has_params?
54
- params.values.select(&:present?).any?
56
+ any = false
57
+ list.each do |facet|
58
+ next if facet.hide_in_selected?
59
+ any = true if facet.params.present?
60
+ end
61
+ any
55
62
  end
56
63
 
57
64
  protected
@@ -84,6 +91,10 @@ module FacetedSearch
84
91
  add_facet FullTree, value, options
85
92
  end
86
93
 
94
+ def filter_with_range(value, options = {})
95
+ add_facet Range, value, options
96
+ end
97
+
87
98
  def params_for(value)
88
99
  @params[value] if @params.has_key? value
89
100
  end
@@ -2,7 +2,14 @@ module FacetedSearch
2
2
  class Facets::Date < Facets::DefaultList
3
3
 
4
4
  def source
5
- @options[:source] || @facets.model.send(:all).pluck(name).compact.map(&:year).uniq.sort
5
+ @source ||= begin
6
+ if @options[:source].present?
7
+ @options[:source]
8
+ else
9
+ results = params_array.blank? ? facets.results : facets.results_except(@name)
10
+ results.send(:all).pluck(name).compact.map(&:year).uniq.sort
11
+ end
12
+ end
6
13
  end
7
14
 
8
15
  def order
@@ -19,11 +26,10 @@ module FacetedSearch
19
26
  end
20
27
 
21
28
  def values
22
- unless @values
23
- @values = source
24
- @values.reverse! unless order == :asc
29
+ @values ||= begin
30
+ values = (source | params_array.map(&:to_i)).sort
31
+ order == :asc ? values : values.reverse
25
32
  end
26
- @values
27
33
  end
28
34
  end
29
35
  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,12 @@ 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
- unless @values
29
+ @values ||= begin
30
30
  joined_table = facets.model_table_name.to_sym
31
- @values = source.all.joins(joined_table).where(joined_table => { id: facets.results }).distinct
31
+ results = params_array.blank? ? facets.results : facets.results_except(@name)
32
+ values = source.all.joins(joined_table)
33
+ values.where(joined_table => { id: results }).or(values.where(id: params_array)).distinct
32
34
  end
33
- @values
34
35
  end
35
36
 
36
37
  def value_selected?(value)
@@ -2,6 +2,14 @@ module FacetedSearch
2
2
  class Facets::PrimitiveList < Facets::DefaultList
3
3
 
4
4
  def source
5
+ @source ||= begin
6
+ if @options[:source].present?
7
+ @options[:source]
8
+ else
9
+ results = params_array.compact.blank? ? facets.results : facets.results_except(@name)
10
+ results.send(:all).where("#{field} IS NOT NULL")
11
+ end
12
+ end
5
13
  @options[:source].where("#{field} IS NOT NULL")
6
14
  end
7
15
 
@@ -22,11 +30,10 @@ module FacetedSearch
22
30
  end
23
31
 
24
32
  def values
25
- unless @values
26
- @values = source.pluck(field).uniq.reject(&:empty?).sort
27
- @values.reverse! unless order == :asc
33
+ @values ||= begin
34
+ values = (source.pluck(field).uniq.reject(&:blank?) | params_array.compact).sort
35
+ order == :asc ? values : values.reverse
28
36
  end
29
- @values
30
37
  end
31
38
  end
32
39
  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,10 +7,10 @@ reset ||= 'Reset'
7
7
  <ul class="faceted__facets-selected list-inline">
8
8
  <% facets.list.each do |facet| %>
9
9
  <%
10
- next if facet.path_pattern?
10
+ next if facet.hide_in_selected?
11
11
  partial = "#{facet.kind.underscore}/selected"
12
12
  %>
13
- <%= render partial, facet: facet %>
13
+ <%= render partial, facet: facet, anchor: anchor %>
14
14
  <% end %>
15
15
  </ul>
16
16
  <% end %>
@@ -6,7 +6,7 @@
6
6
  <%= render 'faceted_search/facets/facet-selected',
7
7
  title: facet.title,
8
8
  value: display_value,
9
- path: facet.facets.path_for(facet, identifier) %>
9
+ path: facet.facets.path_for(facet, identifier) + anchor %>
10
10
  <% end %>
11
11
  <% end %>
12
12
  <% end %>
@@ -4,7 +4,7 @@
4
4
  <%= render 'faceted_search/facets/facet-selected',
5
5
  title: facet.title,
6
6
  value: year,
7
- path: facet.facets.path_for(facet, year) %>
7
+ path: facet.facets.path_for(facet, year) + anchor %>
8
8
  <% end %>
9
9
  <% end %>
10
10
  <% 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>
@@ -1,5 +1,6 @@
1
1
  <% if facet.values.any? %>
2
2
  <%= render 'faceted_search/facets/full_tree/values-selected',
3
3
  values: facet.values_with_parent(nil),
4
- facet: facet %>
4
+ facet: facet,
5
+ anchor: anchor %>
5
6
  <% end %>
@@ -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>
@@ -6,7 +6,7 @@
6
6
  <%= render 'faceted_search/facets/facet-selected',
7
7
  title: facet.title,
8
8
  value: display_value,
9
- path: facet.facets.path_for(facet, identifier) %>
9
+ path: facet.facets.path_for(facet, identifier) + anchor %>
10
10
  <% end %>
11
11
  <% end %>
12
12
  <% end %>
@@ -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 %>" />
@@ -3,5 +3,5 @@
3
3
  <%= render 'faceted_search/facets/facet-selected',
4
4
  title: facet.title,
5
5
  value: value,
6
- path: facet.facets.path_for(facet, nil) %>
6
+ path: facet.facets.path_for(facet, nil) + anchor %>
7
7
  <% end %>
@@ -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',
@@ -1,3 +1,3 @@
1
1
  module FacetedSearch
2
- VERSION = '3.5.3'
2
+ VERSION = '3.5.9'
3
3
  end
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.3
4
+ version: 3.5.9
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-27 00:00:00.000000000 Z
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