generic_search 1.3.2 → 1.4.1
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 +4 -4
- data/lib/generic_search.rb +16 -7
- data/lib/generic_search/build_methods.rb +18 -3
- data/lib/generic_search/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 686efd907cbea7e5870848642937708699c938c3
|
4
|
+
data.tar.gz: 8c80156de86a165d1b2bc8c6d617693173985369
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f83bfb0218639c89fd785e262616f52b7d8250d106c7fc46670864e89e96c0710b0e8e725432bcf741b80a7fc3281186971bf4df36aca4c14f2d91039358593
|
7
|
+
data.tar.gz: f1912676db4fc02ea50e620d94cdd7ef4e527b1aaff586895cb72c157a48819fae15725695c2088322edb4106c725134de21f8144993888189dfebd5312b69dd
|
data/lib/generic_search.rb
CHANGED
@@ -27,7 +27,7 @@ module GenericSearch
|
|
27
27
|
include GenericSearch::BuildMethods
|
28
28
|
|
29
29
|
# Clause attributes
|
30
|
-
attr_accessor :where, :includes, :joins, :select, :group, :limit, :start, :sort_order, :options
|
30
|
+
attr_accessor :where, :includes, :joins, :select, :group, :having, :limit, :start, :sort_order, :options
|
31
31
|
|
32
32
|
# Utility attributes
|
33
33
|
attr_accessor :base_class, :base_table, :grouped_results, :params
|
@@ -71,6 +71,7 @@ module GenericSearch
|
|
71
71
|
self.build_where(params[:query])
|
72
72
|
self.build_results(params[:results])
|
73
73
|
self.build_group(params[:group])
|
74
|
+
self.build_having(params[:having])
|
74
75
|
self.build_options(params[:options])
|
75
76
|
self.build_limit(params[:limit])
|
76
77
|
self.build_start(params[:start])
|
@@ -110,9 +111,8 @@ module GenericSearch
|
|
110
111
|
# selected_fields << attrs[:include]
|
111
112
|
# end
|
112
113
|
#end
|
113
|
-
#
|
114
114
|
|
115
|
-
self.results = self.base_class.where(self.where).joins(self.joins).includes(self.includes).
|
115
|
+
self.results = self.base_class.where(self.where).joins(self.joins).includes(self.includes).reorder(self.sort_order)
|
116
116
|
|
117
117
|
#result_list = @model_class.joins(@joins).includes(includes).where(@where_clause).distinct
|
118
118
|
|
@@ -136,8 +136,19 @@ module GenericSearch
|
|
136
136
|
end
|
137
137
|
|
138
138
|
# TODO: Test required
|
139
|
-
|
140
|
-
|
139
|
+
|
140
|
+
if self.options[:no_grouped_results]
|
141
|
+
if self.group
|
142
|
+
self.results = self.results.group(self.group)
|
143
|
+
end
|
144
|
+
|
145
|
+
if self.having
|
146
|
+
self.results = self.results.having(self.having)
|
147
|
+
end
|
148
|
+
else
|
149
|
+
if self.group
|
150
|
+
group_result_counts = self.results.group(self.group).count
|
151
|
+
end
|
141
152
|
end
|
142
153
|
|
143
154
|
# ============== Group result processing
|
@@ -168,7 +179,6 @@ module GenericSearch
|
|
168
179
|
}
|
169
180
|
end
|
170
181
|
else
|
171
|
-
|
172
182
|
results = if self.options[:no_results]
|
173
183
|
[]
|
174
184
|
else
|
@@ -179,7 +189,6 @@ module GenericSearch
|
|
179
189
|
end
|
180
190
|
|
181
191
|
group_hsh = [{:num_results => self.results.length, :results => results}]
|
182
|
-
|
183
192
|
end
|
184
193
|
|
185
194
|
self.grouped_results = group_hsh
|
@@ -122,15 +122,18 @@ module GenericSearch
|
|
122
122
|
"= '#{value}'"
|
123
123
|
end
|
124
124
|
"\"#{table}\".\"#{config[:field]}\" #{subQuery}"
|
125
|
-
elsif operator == '=' and value.include?('
|
125
|
+
elsif operator == '=' and value.include?('|')
|
126
126
|
|
127
|
-
value = value.gsub(/\s
|
127
|
+
value = value.gsub(/\s*\|\s*/, ' OR ').split(/(AND|OR)/)
|
128
128
|
.collect do |val|
|
129
129
|
val.match(/(AND|OR)/) ? val : "\"#{table}\".\"#{key}\" #{operator} '#{val.strip}'"
|
130
130
|
end.join(' ')
|
131
131
|
|
132
132
|
"(#{value})"
|
133
133
|
|
134
|
+
elsif operator == '=' and value.include?(',')
|
135
|
+
# AND Support should be handled in a different way
|
136
|
+
# using group=user.id, having='ARRAY_AGG(users.id) @> ARRAY[23, 34, 45]::integer[]'
|
134
137
|
else
|
135
138
|
"\"#{table}\".\"#{key}\" #{operator} '#{value}'"
|
136
139
|
end
|
@@ -138,7 +141,7 @@ module GenericSearch
|
|
138
141
|
column_names << key
|
139
142
|
end
|
140
143
|
|
141
|
-
query_per_table << single_search_param
|
144
|
+
query_per_table << single_search_param if single_search_param
|
142
145
|
end
|
143
146
|
|
144
147
|
self.validate_columns(table, column_names, :query)
|
@@ -221,6 +224,14 @@ module GenericSearch
|
|
221
224
|
|
222
225
|
end
|
223
226
|
|
227
|
+
def build_having(having)
|
228
|
+
if having.blank?
|
229
|
+
return
|
230
|
+
end
|
231
|
+
|
232
|
+
self.having = having.gsub(/(^"|"$)/, '').strip
|
233
|
+
end
|
234
|
+
|
224
235
|
def build_sort_order(sort_order)
|
225
236
|
self.sort_order = if sort_order.nil?
|
226
237
|
"\"#{self.base_table}\".\"id\" ASC"
|
@@ -269,6 +280,10 @@ module GenericSearch
|
|
269
280
|
self.options[:distinct] = true
|
270
281
|
end
|
271
282
|
|
283
|
+
if options.include? 'no_grouped_results'
|
284
|
+
self.options[:no_grouped_results] = true
|
285
|
+
end
|
286
|
+
|
272
287
|
end
|
273
288
|
|
274
289
|
def build_response
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: generic_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Hayes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|