co-elastic-query 0.0.3 → 1.0.0

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: 9bd337a7275ec8cec28308fad9de92bf3a0c6564
4
- data.tar.gz: 457927186441945763961a96ec56ecaf563e3be7
3
+ metadata.gz: c6201d8ff96b8b7a0f832da3f041ce68d1e7c13e
4
+ data.tar.gz: 301ecffff574afe0c610b239d504a25d54e9d0e7
5
5
  SHA512:
6
- metadata.gz: 848c7bcfce64a91f66a998461773148d74a7e3850de9ab553546aced805bdca7805b105f65a1138d65206cd2c645b8cb5ef9811c0cd09fb66fe25a1c907528f5
7
- data.tar.gz: d7aa50ade0d46c16978b56611f53b1d6eb57df3ce34f46b97b96a08fb8200a0d1d80d6cde2e88fe2dffcc3c140efb88220ae8dbbb42ae98f23b2d82920793976
6
+ metadata.gz: 036bc57e784220cddae897e99ef50834508c24fccf6c1a215d392a3a90fa23971cbe89e6204a740f2042529de9df025452a4b59881c7d1136d6258779ecad60a
7
+ data.tar.gz: c42ef837af6e2deceba86a782fcd8ac1c075032f55b5e1854f9bd3ed5fefacf4ac8c29e0cf71bbde12de9ace5e273f6642608035a75e914a720f23a3b1b120df
@@ -40,6 +40,15 @@ class Elastic
40
40
  @orFilter.merge!(filters)
41
41
  end
42
42
 
43
+ # Applys the query to child objects
44
+ def has_child(name)
45
+ @hasChild = name
46
+ end
47
+
48
+ def has_parent(name)
49
+ @hasParent = name
50
+ end
51
+
43
52
  def range(filter)
44
53
  @rangeFilter ||= []
45
54
  @rangeFilter << filter
@@ -123,16 +132,68 @@ class Elastic
123
132
 
124
133
  if @search.present?
125
134
  # Break the terms up purely on whitespace
126
- {
127
- query: {
128
- query_string: {
129
- query: '*' + @search.scan(/\S+/).join('* *') + '*'
130
- }
131
- },
132
- filters: fieldfilters,
133
- offset: @offset,
134
- limit: @limit
135
- }
135
+ query_obj = nil
136
+
137
+ # update search string
138
+ @search << '*'
139
+
140
+ if @hasChild || @hasParent
141
+ should = [{
142
+ simple_query_string: {
143
+ query: @search
144
+ }
145
+ }]
146
+
147
+ if @hasChild
148
+ should << {
149
+ has_child: {
150
+ type: @hasChild,
151
+ query: {
152
+ simple_query_string: {
153
+ query: @search
154
+ }
155
+ }
156
+ }
157
+ }
158
+ end
159
+
160
+ if @hasParent
161
+ should << {
162
+ has_parent: {
163
+ parent_type: @hasParent,
164
+ query: {
165
+ simple_query_string: {
166
+ query: @search
167
+ }
168
+ }
169
+ }
170
+ }
171
+ end
172
+
173
+ query_obj = {
174
+ query: {
175
+ bool: {
176
+ should: should
177
+ }
178
+ },
179
+ filters: fieldfilters,
180
+ offset: @offset,
181
+ limit: @limit
182
+ }
183
+ else
184
+ query_obj = {
185
+ query: {
186
+ simple_query_string: {
187
+ query: @search
188
+ }
189
+ },
190
+ filters: fieldfilters,
191
+ offset: @offset,
192
+ limit: @limit
193
+ }
194
+ end
195
+
196
+ query_obj
136
197
  else
137
198
  {
138
199
  sort: @sort || [{created_at: 'desc'}],
@@ -208,7 +269,7 @@ class Elastic
208
269
  queries.unshift(opt[:query])
209
270
 
210
271
  filters = opt[:filters] || []
211
- filters.unshift({term: {type: @filter}})
272
+ filters.unshift({type: {value: @filter}})
212
273
 
213
274
  query = {
214
275
  index: @index,
@@ -1,3 +1,3 @@
1
1
  module CoElasticQuery
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
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: 0.0.3
4
+ version: 1.0.0
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: 2014-10-23 00:00:00.000000000 Z
12
+ date: 2015-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  requirements: []
90
90
  rubyforge_project:
91
- rubygems_version: 2.2.2
91
+ rubygems_version: 2.4.5
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Elasticsearch query generator