create_custom_attributes 0.5.14 → 0.5.15

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
  SHA1:
3
- metadata.gz: a82b2f25d17e3ef2765629bedc963acbc6ec9378
4
- data.tar.gz: 5d395bcea5b5de1dde9d660be8c1785b8414fd3e
3
+ metadata.gz: bcd5b48d261a8d97dc3d171d34b7cd822b4e8a12
4
+ data.tar.gz: 3cdfe34ec1454b14dc21fba38f9c169a16154857
5
5
  SHA512:
6
- metadata.gz: 5f32f954866a102877e87fc7ca7e4a357d3327624f2626e6c9381b13bd766cc348472dc2076891c1728f9d8a62c382dd1a31a3bb53508489aa6be861b1301cca
7
- data.tar.gz: 765023bf69179dd28ac30e53381023033c56e2d73656265d22c8519eae060217d145f11e714c69145873bab6ebcb3b89c3b0d0fe5b203c8d99d422d12597c649
6
+ metadata.gz: 9bed5e3b463fc71b5c01adcf761c41d6842b759357744cb26715cdb0b9a7e81b701e557a7635e536c94b03dac12cd496c4887df110cfd8f97d9ba5b26aec6d81
7
+ data.tar.gz: a2f69fed3cedb1be241076befb47d3a2af3f9746575b9d73e9008d9e8376a889c0f0f9999d57e60f8ee059a04949b54916f9d486527597123fe3347b605a0605
@@ -3,7 +3,7 @@ require 'custom_attributes/search_query_field'
3
3
  module CustomAttributes
4
4
  # Builds a query in elastic search DSL
5
5
  class SearchQuery
6
- attr_accessor :customizable, :query, :field_list, :defaults, :sort_by, :page, :per_page, :match_any, :filter_by
6
+ attr_accessor :customizable, :query, :field_list, :defaults, :sort_by, :page, :per_page, :match_any, :filter_by, :filter_any
7
7
 
8
8
  def build
9
9
  {
@@ -54,6 +54,10 @@ module CustomAttributes
54
54
  @match_any
55
55
  end
56
56
 
57
+ def filter_any?
58
+ @filter_any
59
+ end
60
+
57
61
  def default_fields
58
62
  default_fields = {
59
63
  custom_fields: Hash[customizable.available_custom_fields
@@ -73,7 +77,7 @@ module CustomAttributes
73
77
  private
74
78
 
75
79
  def subquery
76
- filter = filter_hash_to_term_array + [{ term: { visible_in_search: true } }]
80
+ filter = filter_any_decorator(filter_hash_to_term_array) + [{ term: { visible_in_search: true } }]
77
81
 
78
82
  # match all documents if no particular query isset
79
83
  if query == '*' && field_list.empty?
@@ -89,6 +93,7 @@ module CustomAttributes
89
93
  }
90
94
  end
91
95
 
96
+
92
97
  {
93
98
  bool: {
94
99
  filter: filter
@@ -159,7 +164,11 @@ module CustomAttributes
159
164
  def filter_hash_to_term_array
160
165
  hash_to_array(filter_by) do |type, field_slug, field_data|
161
166
  if type == :custom_fields
162
- custom_query_scaffold(field_data, field_slug, true)
167
+ if field_data.is_a? Array
168
+ field_data.map { |fd| custom_query_scaffold(fd, field_slug, true) }
169
+ else
170
+ custom_query_scaffold(field_data, field_slug, true)
171
+ end
163
172
  else
164
173
  key = 'term'
165
174
  key = key.pluralize if field_data.is_a? Array
@@ -205,6 +214,19 @@ module CustomAttributes
205
214
  end
206
215
  end
207
216
 
217
+ def filter_any_decorator(filter_array)
218
+ if !filter_any?
219
+ filter_array
220
+ else
221
+ [{
222
+ bool: {
223
+ should: filter_hash_to_term_array,
224
+ minimum_should_match: 1
225
+ }
226
+ }]
227
+ end
228
+ end
229
+
208
230
  def custom_query_scaffold(query, field_slug, filter = false)
209
231
  condition = { match: { 'custom_field_values.value' => query } }
210
232
  condition = { term: { 'custom_field_values.value.raw' => query } } if filter
@@ -1,3 +1,3 @@
1
1
  module CustomAttributes
2
- VERSION = '0.5.14'.freeze
2
+ VERSION = '0.5.15'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: create_custom_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.14
4
+ version: 0.5.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Grützmacher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-06 00:00:00.000000000 Z
11
+ date: 2018-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails