faceted_search 3.4.6 → 3.5.4

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: 9e9f81eccfba92e5b5cdee2597cbb3398441e50509c3ef5a03917ede6640f344
4
- data.tar.gz: d25738a940c0bbfcb7e971d65df5347fe7ca93e22e756d1f3cd2b2ff0a207e19
3
+ metadata.gz: f9c031c6042e6795df7c7465fba26d1ff6e8d8ad3c7f3db94859febdcf3df6e0
4
+ data.tar.gz: c534ffb91303aaa601e530bd2271bb36dcef60ec01d04ba97ee74645f8968e86
5
5
  SHA512:
6
- metadata.gz: 4ef30658dc5d4c0bea74517853adcc22641ad5b2b6d51f8d18700576c293bb92579e592667a7fa200df22b8480d23161df53a4b253725922f0ceac5249e26fbc
7
- data.tar.gz: 204033e66314157a25b00f15bfc6f51650b62ce1dc7979f462394b27bfdec9f4cec9bc1aab88cae1ae223c4979ae8d900ec198b4aafe9fb167fa5b29179ce8e3
6
+ metadata.gz: f062d6086f4608816429ad31f69cf706f7a7868e486183a3c42f7c1d546190c8142d8dcc6b2cb3fb91901b0f26f64cf49c848a3c5de37407d7cd9150ab0ca737
7
+ data.tar.gz: 90669a44d5ba16929296b22854a80446ddb88cde6ea2df4e38e96495e25ab61b3e7b38788fefce07ce78d5a55162bf11b9cef99106616f6bd9388da228f68b13
data/README.md CHANGED
@@ -56,6 +56,24 @@ Create a model defining your facets:
56
56
  # children.order(:title)
57
57
  # }
58
58
  # }
59
+
60
+ # Other option, with searchable (SEO) categories
61
+ filter_with_full_tree :categories, {
62
+ habtm: true,
63
+ searchable: true,
64
+ path_pattern: Proc.new { |category_id|
65
+ Rails.application.routes.url_helpers.category_path(category_id)
66
+ }
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
+ }
59
77
  end
60
78
  end
61
79
 
@@ -19,10 +19,18 @@ module FacetedSearch
19
19
  end
20
20
 
21
21
  def path_for(facet, value)
22
- p = path
23
- list.each do |current_facet|
24
- p += current_facet == facet ? current_facet.path_for(value)
25
- : current_facet.path
22
+ if facet.path_pattern?
23
+ p = "#{facet.path_pattern.call(value)}#{path}"
24
+ list.each do |current_facet|
25
+ p += current_facet.path if current_facet != facet
26
+ end
27
+ else
28
+ p = path
29
+ list.each do |current_facet|
30
+ next if current_facet.path_pattern?
31
+ p += current_facet == facet ? current_facet.path_for(value)
32
+ : current_facet.path
33
+ end
26
34
  end
27
35
  p
28
36
  end
@@ -31,7 +39,7 @@ module FacetedSearch
31
39
  unless @results
32
40
  scope = @model
33
41
  list.each do |facet|
34
- scope = facet.add_scope(scope)
42
+ scope = facet.add_scope(scope) unless facet.ignore_scope?
35
43
  end
36
44
  @results = scope.distinct
37
45
  end
@@ -76,6 +84,10 @@ module FacetedSearch
76
84
  add_facet FullTree, value, options
77
85
  end
78
86
 
87
+ def filter_with_range(value, options = {})
88
+ add_facet Range, value, options
89
+ end
90
+
79
91
  def params_for(value)
80
92
  @params[value] if @params.has_key? value
81
93
  end
@@ -13,6 +13,26 @@ module FacetedSearch
13
13
  @options[:title] || name.to_s.humanize.titleize
14
14
  end
15
15
 
16
+ def searchable
17
+ @options[:searchable] || false
18
+ end
19
+
20
+ def path_pattern
21
+ @options[:path_pattern] || false
22
+ end
23
+
24
+ def path_pattern?
25
+ @options.has_key? :path_pattern
26
+ end
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
+
16
36
  def kind
17
37
  self.class.to_s
18
38
  end
@@ -28,7 +28,7 @@ module FacetedSearch
28
28
  def values
29
29
  unless @values
30
30
  joined_table = facets.model_table_name.to_sym
31
- @values = source.all.joins(joined_table).where(joined_table => { id: facets.model }).distinct
31
+ @values = source.all.joins(joined_table).where(joined_table => { id: facets.results }).distinct
32
32
  end
33
33
  @values
34
34
  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,7 +6,10 @@ 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" %>
9
+ <%
10
+ next if facet.hide_in_selected?
11
+ partial = "#{facet.kind.underscore}/selected"
12
+ %>
10
13
  <%= render partial, facet: facet %>
11
14
  <% end %>
12
15
  </ul>
@@ -18,7 +21,7 @@ reset ||= 'Reset'
18
21
  <%= render partial, facet: facet, anchor: anchor %>
19
22
  <% end %>
20
23
  <li class="faceted__facet__reinit">
21
- <a href="<%= facets.path %>">
24
+ <a href="<%= facets.path %>" rel="nofollow">
22
25
  <i class="fas fa-ban"></i>
23
26
  <%= reset %>
24
27
  </a>
@@ -0,0 +1,5 @@
1
+ <% if searchable %>
2
+ <%= link_to display_value, path %>
3
+ <% else %>
4
+ <%= link_to display_value, path, rel: 'nofollow' %>
5
+ <% end %>
@@ -1,6 +1,6 @@
1
1
  <li class=" faceted__facet-selected
2
2
  list-inline-item">
3
- <%= link_to path, class: 'badge badge-light' do %>
3
+ <%= link_to path, class: 'badge badge-light', rel: 'nofollow' do %>
4
4
  <% unless title %>
5
5
  <span class="faceted__facet-selected__title d-none">
6
6
  <%= title %>
@@ -14,9 +14,12 @@
14
14
  onclick="window.location.href='<%= path %>'"
15
15
  <%= 'checked' if selected %>
16
16
  />
17
- <%= link_to name, path %>
17
+ <%= render 'faceted_search/link',
18
+ display_value: name,
19
+ path: path,
20
+ searchable: facet.searchable %>
18
21
  </li>
19
22
  <% end %>
20
23
  </ul>
21
24
  </li>
22
- <% end %>
25
+ <% end %>
@@ -4,9 +4,12 @@
4
4
  <ol class="faceted__facet__date list-unstyled">
5
5
  <% facet.values.each do |year| %>
6
6
  <li class="faceted__facet__date__value <%= 'faceted__facet__date__value--selected' if facet.value_selected?(year) %>">
7
- <%= link_to year, facet.facets.path_for(facet, year) + anchor %>
7
+ <%= render 'faceted_search/link',
8
+ display_value: year,
9
+ path: facet.facets.path_for(facet, year) + anchor,
10
+ searchable: facet.searchable %>
8
11
  </li>
9
12
  <% end %>
10
13
  </ol>
11
14
  </li>
12
- <% end %>
15
+ <% end %>
@@ -1,11 +1,10 @@
1
1
  <% values.each do |value| %>
2
- <%
3
- display_value = facet.display_method.call(value)
4
- identifier = value.send facet.find_by
5
- path = facet.facets.path_for(facet, identifier)
6
- %>
2
+ <% identifier = value.send facet.find_by %>
7
3
  <li class="faceted__facet__full_tree__value<%= '--selected' if facet.value_selected?(identifier) %> dd-item <%= 'dd-item--selected' if facet.value_selected?(identifier) %>">
8
- <%= link_to display_value, path %>
4
+ <%= render 'faceted_search/link',
5
+ display_value: facet.display_method.call(value),
6
+ path: facet.facets.path_for(facet, identifier),
7
+ searchable: facet.searchable %>
9
8
  <% child_values = facet.values_with_parent(value.id) %>
10
9
  <% if child_values.any? %>
11
10
  <ol class="dd-list">
@@ -8,9 +8,12 @@
8
8
  display_value = facet.display_method.call(value)
9
9
  %>
10
10
  <li class="faceted__facet__list__value <%= 'faceted__facet__list__value--selected' if facet.value_selected?(identifier) %>">
11
- <%= link_to display_value, facet.facets.path_for(facet, identifier) + anchor %>
11
+ <%= render 'faceted_search/link',
12
+ display_value: display_value,
13
+ path: facet.facets.path_for(facet, identifier) + anchor,
14
+ searchable: facet.searchable %>
12
15
  </li>
13
16
  <% end %>
14
17
  </ol>
15
18
  </li>
16
- <% end %>
19
+ <% end %>
@@ -12,7 +12,10 @@
12
12
  onclick="window.location.href='<%= path %>'"
13
13
  <%= 'checked' if selected %>
14
14
  />
15
- <%= link_to identifier, path %>
15
+ <%= render 'faceted_search/link',
16
+ display_value: identifier,
17
+ path: path,
18
+ searchable: facet.searchable %>
16
19
  </li>
17
20
  <% end %>
18
21
  </ul>
@@ -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 %>" />
@@ -9,7 +9,7 @@
9
9
  path = facet.facets.path_for(facet, identifier)
10
10
  %>
11
11
  <div class="faceted__facet__tree__back">
12
- <%= link_to path do %>
12
+ <%= link_to path, rel: 'nofollow' do %>
13
13
  <i class="fas fa-arrow-left"></i> <%= display_value %>
14
14
  <% end %>
15
15
  </div>
@@ -23,10 +23,13 @@
23
23
  path = facet.facets.path_for(facet, identifier)
24
24
  %>
25
25
  <li class="faceted__facet__tree__value">
26
- <%= link_to display_value, path %>
26
+ <%= render 'faceted_search/link',
27
+ display_value: display_value,
28
+ path: path,
29
+ searchable: facet.searchable %>
27
30
  </li>
28
31
  <% end %>
29
32
  </ol>
30
33
  </div>
31
34
  </li>
32
- <% end %>
35
+ <% end %>
@@ -1,3 +1,3 @@
1
1
  module FacetedSearch
2
- VERSION = '3.4.6'
2
+ VERSION = '3.5.4'
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.4.6
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-26 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,9 +137,11 @@ 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
144
+ - app/views/faceted_search/_link.html.erb
143
145
  - app/views/faceted_search/facets/_facet-selected.html.erb
144
146
  - app/views/faceted_search/facets/checkboxes/_all.html.erb
145
147
  - app/views/faceted_search/facets/checkboxes/_selected.html.erb
@@ -153,6 +155,8 @@ files:
153
155
  - app/views/faceted_search/facets/list/_selected.html.erb
154
156
  - app/views/faceted_search/facets/primitive_list/_all.html.erb
155
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
156
160
  - app/views/faceted_search/facets/text/_all.html.erb
157
161
  - app/views/faceted_search/facets/text/_selected.html.erb
158
162
  - app/views/faceted_search/facets/tree/_all.html.erb