faceted_search 3.6.0 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f3a631dcd6d16b556a25e2db756808ce7173708ccd02a23fc6854c5e8c30f01
4
- data.tar.gz: ea0745c3ed87fd105f497dadd007a8417a01c1cc6f2925e0c93fe0aaa3e208d9
3
+ metadata.gz: cf6eb515ded15419dfe734adabf061401175de3e53282913e3fed8d34925bed0
4
+ data.tar.gz: '0668e4c8c20ece2f177cf517dadb120f3662dafaa66948f2c311a903f6ff8983'
5
5
  SHA512:
6
- metadata.gz: dbe3a9ae5256ba40b72fd9d7cd2568d41bcfa96c13c999652e3dfc55894c4eb5dd6fbf1b580e98bb79183243d9798f303e2122de481b3d47d0582ab18c1c0800
7
- data.tar.gz: d8eb1931049507e9f175c9c08c1e92ed883d87e1f29d21c039a80f50483158e55a75e6453b5c10cb8048af07867abc3e46a379423b42d832487b0a5bf8380b4c
6
+ metadata.gz: 889bac63c9c66f13e3f17a811a2468a53511b7626bb69b8872bae1582ff5a3cde8d7c96c41e2bb3d2a09be3452b08a0562faeadd6173dbf41c6a8fbc5472c228
7
+ data.tar.gz: 9f0519609d363702df936afe08ead0603257ecdd63466cd970f54eeb895455728416f31884341f8dc69c7e3f5059abe29ae2bdf975383102191ffaaeca18f9e8
@@ -18,20 +18,15 @@ module FacetedSearch
18
18
  # and return the modified scope
19
19
  def add_scope(scope)
20
20
  return scope if params_array.blank?
21
-
22
- habtm? ? scope.joins(name).where(name => { find_by => params_array })
23
- : scope.where(name => params_array)
21
+ habtm? ? add_scope_with_habtm_true(scope)
22
+ : add_scope_with_habtm_false(scope)
24
23
  end
25
24
 
26
25
  # Show all values that have corresponding results with the current params.
27
26
  # This is a regular SQL inner join.
28
27
  def values
29
- @values ||= begin
30
- joined_table = facets.model_table_name.to_sym
31
- results = params_array.blank? ? facets.results : facets.results_except(param_name)
32
- values = source.all.joins(joined_table)
33
- values.where(joined_table => { id: results }).or(values.where(id: params_array)).distinct
34
- end
28
+ @values ||= habtm? ? values_with_habtm_true
29
+ : values_with_habtm_false
35
30
  end
36
31
 
37
32
  def value_selected?(value)
@@ -48,6 +43,31 @@ module FacetedSearch
48
43
 
49
44
  protected
50
45
 
46
+ def add_scope_with_habtm_true(scope)
47
+ scope.joins(name).where(name => { find_by => params_array })
48
+ end
49
+
50
+ def add_scope_with_habtm_false(scope)
51
+ scope.where(name => params_array)
52
+ end
53
+
54
+ def results
55
+ params_array.blank? ? facets.results : facets.results_except(param_name)
56
+ end
57
+
58
+ def values_with_habtm_true
59
+ joined_table = facets.model_table_name.to_sym
60
+ values = source.all.joins(joined_table)
61
+ values.where(joined_table => { id: results }).or(values.where(id: params_array)).distinct
62
+ rescue
63
+ end
64
+
65
+ def values_with_habtm_false
66
+ property = "#{name}_id"
67
+ ids = results.pluck property
68
+ source.where(id: ids)
69
+ end
70
+
51
71
  def params_array
52
72
  @params_array ||= @params.to_s.split(',')
53
73
  end
@@ -1,3 +1,3 @@
1
1
  module FacetedSearch
2
- VERSION = '3.6.0'
2
+ VERSION = '3.6.1'
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.6.0
4
+ version: 3.6.1
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: 2023-01-09 00:00:00.000000000 Z
13
+ date: 2023-03-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  - !ruby/object:Gem::Version
183
183
  version: '0'
184
184
  requirements: []
185
- rubygems_version: 3.3.7
185
+ rubygems_version: 3.4.6
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: Faceted search with Active Record