co-elastic-query 1.0.2 → 1.0.3

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
  SHA1:
3
- metadata.gz: cb06a0255fd72056eede70e58e97638b3b0187ff
4
- data.tar.gz: 07e712c603aa04b0a4dc94dc4a424bbd86bb4729
3
+ metadata.gz: 29167287ed81d7deb378c47079d78638cbb981b3
4
+ data.tar.gz: 9b45192f4c28d0e875c99a9c2d11dc084e01d13c
5
5
  SHA512:
6
- metadata.gz: 366a55f2a4f06023536220dec23610ab01107f46b2d11399848424b489f8ad725c2bd3c00cbff527cc909e2eccee15829a1e77bc3654fecc9f53d6948080e558
7
- data.tar.gz: 1b1d8c3dc6d5ec94b02af7aa859ac17eba936596f5a3203e4c9e864aec5c4302d4dbb7f1d1bad4025913bb7bd4c6bababd2b77548fabd1315f090e5a1f2477fd
6
+ metadata.gz: 47c03c8bcddb3dac6e7a9752809e0ca059f5ac66db64dfeb59fd4876031eab3db3f37a164e8e89d374b7cf2c96eda71a17f5835bdae0e46af9fb5bbc4462164e
7
+ data.tar.gz: 1cee889bfd71aa06492c2ac2259aa1350fa17bf776ba8c17cd9d0be916158c8864a4efe920478b34e9b5f38381d7984611c14e91152c098580cbfdf055f99a0d
@@ -6,11 +6,11 @@ class Elastic
6
6
  query = params ? params.permit(:q, :limit, :offset) : {}
7
7
 
8
8
  @filters = nil
9
- @search = query[:q]
9
+ @search = "#{query[:q]}*"
10
10
 
11
11
  @limit = query[:limit] || 20
12
12
  @limit = @limit.to_i
13
- @limit = 50 if @limit > 50
13
+ @limit = 500 if @limit > 500
14
14
 
15
15
  @offset = query[:offset] || 0
16
16
  @offset = offset.to_i
@@ -23,7 +23,9 @@ class Elastic
23
23
  attr_accessor :sort
24
24
 
25
25
  def raw_filter(filter)
26
- @raw_filter = filter
26
+ @raw_filter ||= []
27
+ @raw_filter << filter
28
+ self
27
29
  end
28
30
 
29
31
 
@@ -32,12 +34,14 @@ class Elastic
32
34
  def filter(filters)
33
35
  @filters ||= {}
34
36
  @filters.merge!(filters)
37
+ self
35
38
  end
36
39
 
37
40
  # Like filter however all keys are OR's instead of AND's
38
41
  def or_filter(filters)
39
42
  @orFilter ||= {}
40
43
  @orFilter.merge!(filters)
44
+ self
41
45
  end
42
46
 
43
47
  # Applys the query to child objects
@@ -52,6 +56,7 @@ class Elastic
52
56
  def range(filter)
53
57
  @rangeFilter ||= []
54
58
  @rangeFilter << filter
59
+ self
55
60
  end
56
61
 
57
62
  # Call to add fields that should be missing
@@ -59,14 +64,23 @@ class Elastic
59
64
  def missing(*fields)
60
65
  @missing ||= Set.new
61
66
  @missing.merge(fields)
67
+ self
62
68
  end
63
69
 
64
70
  # The opposite of filter
65
71
  def not(filters)
66
72
  @nots ||= {}
67
73
  @nots.merge!(filters)
74
+ self
68
75
  end
69
76
 
77
+ def exists(*fields)
78
+ @exists ||= Set.new
79
+ @exists.merge(fields)
80
+ self
81
+ end
82
+
83
+
70
84
  def build
71
85
  if @filters
72
86
  fieldfilters = []
@@ -126,17 +140,24 @@ class Elastic
126
140
  end
127
141
  end
128
142
 
143
+ if @exists
144
+ fieldfilters ||= []
145
+
146
+ @exists.each do |field|
147
+ fieldfilters.push({
148
+ exists: { field: field }
149
+ })
150
+ end
151
+ end
152
+
129
153
  if @raw_filter
130
- fieldfilters = @raw_filter
154
+ fieldfilters += @raw_filter
131
155
  end
132
156
 
133
- if @search.present?
157
+ if @search.length > 1
134
158
  # Break the terms up purely on whitespace
135
159
  query_obj = nil
136
160
 
137
- # update search string
138
- @search << '*'
139
-
140
161
  if @hasChild || @hasParent
141
162
  should = [{
142
163
  simple_query_string: {
@@ -293,18 +314,10 @@ class Elastic
293
314
  query[:body].delete(:size)
294
315
  query[:body].delete(:sort)
295
316
 
296
- # if a formatter block is supplied, each loaded record is passed to it
297
- # allowing annotation/conversion of records using data from the model
298
- # and current request (e.g groups are annotated with 'admin' if the
299
- # currently logged in user is an admin of the group). nils are removed
300
- # from the list.
301
317
  Elastic.count(query)[COUNT]
302
318
  end
303
319
 
304
320
 
305
- protected
306
-
307
-
308
321
  def generate_body(builder)
309
322
  opt = builder.build
310
323
 
@@ -1,3 +1,3 @@
1
1
  module CoElasticQuery
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: co-elastic-query
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-27 00:00:00.000000000 Z
12
+ date: 2015-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler