create_custom_attributes 0.5.16 → 0.5.17
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da291bc2e4b77983c12426a2c6b6b9f0aaeb55b3
|
4
|
+
data.tar.gz: d60409a040c85fa5f876adf99f5df1d1213527a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b97b5f9be626f258af322b2cc0e2689df04db66e753cbe93c69069cec151876d596e5691e0d56d39d55959185346ede2bd8e5c9aaf75605e59348c8ac02b3d39
|
7
|
+
data.tar.gz: 505ccd757de9304aa6b2f511bee09a892edb66c90903a015f023060f2e9de1a0d586f0f62e47ff04ffee2cf6540eafa36a0481d6adceb48a6d18c07b82110c97
|
@@ -45,20 +45,20 @@ module CustomAttributes
|
|
45
45
|
self
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
49
|
-
@search_query.
|
48
|
+
def filter_or(field_list)
|
49
|
+
@search_query.filter_or.merge! field_list
|
50
50
|
|
51
51
|
self
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
55
|
-
@search_query.
|
54
|
+
def sort_by(field_list)
|
55
|
+
@search_query.sort_by.merge! field_list
|
56
56
|
|
57
57
|
self
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
61
|
-
@search_query.
|
60
|
+
def match_any
|
61
|
+
@search_query.match_any = true
|
62
62
|
|
63
63
|
self
|
64
64
|
end
|
@@ -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_or
|
7
7
|
|
8
8
|
def build
|
9
9
|
{
|
@@ -35,6 +35,10 @@ module CustomAttributes
|
|
35
35
|
@filter_by ||= {}
|
36
36
|
end
|
37
37
|
|
38
|
+
def filter_or
|
39
|
+
@filter_or ||= {}
|
40
|
+
end
|
41
|
+
|
38
42
|
def sort_by
|
39
43
|
@sort_by ||= {}
|
40
44
|
end
|
@@ -54,10 +58,6 @@ module CustomAttributes
|
|
54
58
|
@match_any
|
55
59
|
end
|
56
60
|
|
57
|
-
def filter_any?
|
58
|
-
@filter_any
|
59
|
-
end
|
60
|
-
|
61
61
|
def default_fields
|
62
62
|
default_fields = {
|
63
63
|
custom_fields: Hash[customizable.available_custom_fields
|
@@ -77,7 +77,7 @@ module CustomAttributes
|
|
77
77
|
private
|
78
78
|
|
79
79
|
def subquery
|
80
|
-
filter =
|
80
|
+
filter = filter_term_array + [{ term: { visible_in_search: true } }]
|
81
81
|
|
82
82
|
# match all documents if no particular query isset
|
83
83
|
if query == '*' && field_list.empty?
|
@@ -161,8 +161,8 @@ module CustomAttributes
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
-
def filter_hash_to_term_array
|
165
|
-
hash_to_array(
|
164
|
+
def filter_hash_to_term_array(filter_list)
|
165
|
+
hash_to_array(filter_list) do |type, field_slug, field_data|
|
166
166
|
if type == :custom_fields
|
167
167
|
if field_data.is_a? Array
|
168
168
|
field_data.map { |fd| custom_query_scaffold(fd, field_slug, true) }
|
@@ -178,6 +178,18 @@ module CustomAttributes
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
|
+
def filter_term_array
|
182
|
+
return filter_hash_to_term_array(filter_by) if filter_or.empty?
|
183
|
+
|
184
|
+
filter_hash = { minimum_should_match: 1 }
|
185
|
+
filter_hash[:must] = filter_hash_to_term_array(filter_by) unless filter_by.empty?
|
186
|
+
filter_hash[:should] = filter_hash_to_term_array(filter_or) unless filter_or.empty?
|
187
|
+
|
188
|
+
[{
|
189
|
+
bool: filter_hash
|
190
|
+
}]
|
191
|
+
end
|
192
|
+
|
181
193
|
def filter_out_custom_fields(fields)
|
182
194
|
return {} if fields[:fields].nil?
|
183
195
|
|
@@ -214,19 +226,6 @@ module CustomAttributes
|
|
214
226
|
end
|
215
227
|
end
|
216
228
|
|
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
|
-
|
230
229
|
def custom_query_scaffold(query, field_slug, filter = false)
|
231
230
|
condition = { match: { 'custom_field_values.value' => query } }
|
232
231
|
condition = { term: { 'custom_field_values.value.raw' => query } } if filter
|