faceted_search 3.5.2 → 3.5.7

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: 598ba312e828e0b31d0b55bc9e936d459ea94971b452c7b6f4c08654ed2db026
4
- data.tar.gz: 77924d76aa8909f4aef080e73e8178ac9aa154d0ef6152d212d140526e1c3ed7
3
+ metadata.gz: 80006422a406840a486d9c8f5a50e1a2425057b285af095e95ee359021a1c1d7
4
+ data.tar.gz: 578682f035d0315fe84a4950e78879eb0f9654b5d9ff2582b091672473c517ff
5
5
  SHA512:
6
- metadata.gz: 54187ff5b302064577535b80c7b5b0ed87e21ed328f11766c2ee7f3c1f8e487d9ed4277d68b2f067cea06df246ded7bc8eb3e49f30208b6b471f5a16606799b3
7
- data.tar.gz: 8f4a9a67d1d9fc3cfd51b4e2330d9367b8e4da5b196e80b430c15f9b3627f913af5984702ba94ffa1c66a11b672a2459b06f7281e87144b75e699f1cd4a11706
6
+ metadata.gz: ee0870c176285f42f78bb0c244a52783dcc54733b1d0ad1fc5a3db88b069b72d0222bc2c87b6873fd1b503f5d5b2f58f6782c905963d38ece704ded9b5b21c0d
7
+ data.tar.gz: f0f3ab3e4019737a2d48a364f74b82bc449a1d8d26f94972d3830dcf8334b61b2d473026832cec7d6247ac8bf88eb59e68f0e03237c6e30e54d88a091d199b5b
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
- 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
@@ -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,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,7 @@ module FacetedSearch
19
26
  end
20
27
 
21
28
  def values
22
- unless @values
23
- @values = source
24
- @values.reverse! unless order == :asc
25
- end
26
- @values
29
+ @values ||= order == :asc ? source : source.reverse
27
30
  end
28
31
  end
29
32
  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
- 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
+ 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,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?).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
@@ -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
- <% partial = "#{facet.kind.underscore}/selected" %>
10
- <%= render partial, facet: facet %>
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 %>
@@ -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.2'
2
+ VERSION = '3.5.7'
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.2
4
+ version: 3.5.7
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