co-elastic-query 3.0.3 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/co-elastic-query.rb +16 -8
- data/lib/co-elastic-query/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: 9b151553366a3789ac06d80546f5eea887afc35f
|
4
|
+
data.tar.gz: 7d45f4eefb2c5052b666d69e5683861b3989df18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6106ba041466def4f08aceffeca77a29294c32d5530e606fd0ac86837ac2397ead9150da20fb8ade3f341d42db31ff78525090e047e1a063a1c48a876cd7dd2b
|
7
|
+
data.tar.gz: c8b0e70ad054708d36af51b780096775b421e888a270392d684ce6e85fa803d9c36c341550392cd71d0ae1381533e5846cf94e21bb65f00ab40a6ef76efbc792
|
data/lib/co-elastic-query.rb
CHANGED
@@ -315,9 +315,11 @@ class Elastic
|
|
315
315
|
SCORE = ['_score'.freeze]
|
316
316
|
INDEX = (ENV['ELASTIC_INDEX'] || 'default').freeze
|
317
317
|
|
318
|
-
def initialize(klass, opts
|
319
|
-
|
320
|
-
|
318
|
+
def initialize(klass = nil, **opts)
|
319
|
+
if klass
|
320
|
+
@klass = klass
|
321
|
+
@filter = klass.design_document
|
322
|
+
end
|
321
323
|
@index = opts[:index] || INDEX
|
322
324
|
@use_couch_type = opts[:use_couch_type] || false
|
323
325
|
end
|
@@ -338,7 +340,11 @@ class Elastic
|
|
338
340
|
# currently logged in user is an admin of the group). nils are removed
|
339
341
|
# from the list.
|
340
342
|
result = Elastic.search(query)
|
341
|
-
records =
|
343
|
+
records = if @klass
|
344
|
+
Array(@klass.find_by_id(result[HITS][HITS].map {|entry| entry[ID]}))
|
345
|
+
else
|
346
|
+
Array(result[HITS][HITS].map { |entry| ::CouchbaseOrm.try_load(entry[ID]) }).compact
|
347
|
+
end
|
342
348
|
results = block_given? ? (records.map {|record| yield record}).compact : records
|
343
349
|
|
344
350
|
# Ensure the total is accurate
|
@@ -377,10 +383,12 @@ class Elastic
|
|
377
383
|
|
378
384
|
filters = opt[:filters] || []
|
379
385
|
|
380
|
-
if @
|
381
|
-
|
382
|
-
|
383
|
-
|
386
|
+
if @filter
|
387
|
+
if @use_couch_type
|
388
|
+
filters.unshift({term: {'doc.type' => @filter}})
|
389
|
+
else
|
390
|
+
filters.unshift({type: {value: @filter}})
|
391
|
+
end
|
384
392
|
end
|
385
393
|
|
386
394
|
{
|
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: 3.0
|
4
|
+
version: 3.1.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: 2017-08-
|
12
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|