stretchy 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stretchy/clauses/base.rb +42 -2
- data/lib/stretchy/results/base.rb +20 -3
- data/lib/stretchy/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: f6b9494adc6453711289b4e3c5321c683d190ab7
|
4
|
+
data.tar.gz: 0d8832b4787080dff61db37429c7cf8d021a0074
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b3bb35dcdeec2eb3745b29c4adfa127e6055c02ed3273a8c308f25135f1dd5a9498b0f3de3c1684934b78f60687a2c56caed3bac45da8a7a0b127f8d7b299cf
|
7
|
+
data.tar.gz: aa4e00a5abda4a8ca7e581ecc5b84a513283deeacc8b295412d4bc561c388c3895562612a0b9a041d9938ab99fa8e8f53cfcefa7ae1c1cdce403b40fe71eef37
|
@@ -23,7 +23,7 @@ module Stretchy
|
|
23
23
|
:aggregate_builder, :inverse, :type, :index_name
|
24
24
|
|
25
25
|
delegate [:request, :response, :results, :ids, :hits,
|
26
|
-
:took, :shards, :total, :max_score] => :query_results
|
26
|
+
:took, :shards, :total, :max_score, :total_pages] => :query_results
|
27
27
|
delegate [:range, :geo] => :where
|
28
28
|
|
29
29
|
#
|
@@ -59,7 +59,7 @@ module Stretchy
|
|
59
59
|
@match_builder = Stretchy::Builders::MatchBuilder.new
|
60
60
|
@where_builder = Stretchy::Builders::WhereBuilder.new
|
61
61
|
@boost_builder = Stretchy::Builders::BoostBuilder.new
|
62
|
-
@aggregate_builder =
|
62
|
+
@aggregate_builder = {}
|
63
63
|
@inverse = options[:inverse]
|
64
64
|
@limit = DEFAULT_LIMIT
|
65
65
|
@offset = DEFAULT_OFFSET
|
@@ -87,6 +87,7 @@ module Stretchy
|
|
87
87
|
def get_limit
|
88
88
|
@limit
|
89
89
|
end
|
90
|
+
alias :limit_value :get_limit
|
90
91
|
|
91
92
|
#
|
92
93
|
# Sets the offset to start returning results at.
|
@@ -101,6 +102,7 @@ module Stretchy
|
|
101
102
|
@offset = num
|
102
103
|
self
|
103
104
|
end
|
105
|
+
alias :per_page :offset
|
104
106
|
|
105
107
|
#
|
106
108
|
# Accessor for `@offset`
|
@@ -110,6 +112,27 @@ module Stretchy
|
|
110
112
|
@offset
|
111
113
|
end
|
112
114
|
|
115
|
+
#
|
116
|
+
# Allows pagination via Kaminari-like accessor
|
117
|
+
# @param num [Integer] Page number. Natural numbers only, **this is not zero-indexed**
|
118
|
+
# @option per_page [Integer] :per_page (DEFAULT_LIMIT) Number of results per page
|
119
|
+
#
|
120
|
+
# @return [self] Allows continuing the query chain
|
121
|
+
def page(num, options = {})
|
122
|
+
@limit = options[:limit] || options[:per_page] || @limit
|
123
|
+
@offset = [(num - 1), 0].max.ceil * @limit
|
124
|
+
self
|
125
|
+
end
|
126
|
+
|
127
|
+
#
|
128
|
+
# Accessor for current page
|
129
|
+
#
|
130
|
+
# @return [Integer] (offset / limit).ceil
|
131
|
+
def get_page
|
132
|
+
(@offset.to_f / @limit).ceil + 1
|
133
|
+
end
|
134
|
+
alias :current_page :get_page
|
135
|
+
|
113
136
|
#
|
114
137
|
# Tells the search to explain the scoring
|
115
138
|
# mechanism for each document.
|
@@ -222,6 +245,23 @@ module Stretchy
|
|
222
245
|
end
|
223
246
|
end
|
224
247
|
|
248
|
+
#
|
249
|
+
# Allows adding raw aggregation JSON to your
|
250
|
+
# query
|
251
|
+
# @param opts = {} [Hash] JSON to aggregate on
|
252
|
+
#
|
253
|
+
# @return [self] Allows continuing the query chain
|
254
|
+
def aggregations(opts = {})
|
255
|
+
@aggregate_builder = @aggregate_builder.merge(opts)
|
256
|
+
self
|
257
|
+
end
|
258
|
+
alias :aggs :aggregations
|
259
|
+
|
260
|
+
def get_aggregations
|
261
|
+
@aggregate_builder
|
262
|
+
end
|
263
|
+
alias :get_aggs :get_aggregations
|
264
|
+
|
225
265
|
#
|
226
266
|
# Accessor for `@inverse`
|
227
267
|
#
|
@@ -6,7 +6,7 @@ module Stretchy
|
|
6
6
|
|
7
7
|
attr_reader :clause, :index_name
|
8
8
|
|
9
|
-
delegate [:type] => :clause
|
9
|
+
delegate [:type, :current_page, :limit_value] => :clause
|
10
10
|
|
11
11
|
def initialize(clause)
|
12
12
|
@clause = clause
|
@@ -16,13 +16,26 @@ module Stretchy
|
|
16
16
|
def limit
|
17
17
|
clause.get_limit
|
18
18
|
end
|
19
|
+
alias :per_page :limit
|
20
|
+
alias :limit_value :limit
|
19
21
|
|
20
22
|
def offset
|
21
23
|
clause.get_offset
|
22
24
|
end
|
23
25
|
|
26
|
+
def page
|
27
|
+
clause.get_page
|
28
|
+
end
|
29
|
+
|
30
|
+
def total_pages
|
31
|
+
[(total.to_f / limit).ceil, 1].max
|
32
|
+
end
|
33
|
+
|
24
34
|
def request
|
25
|
-
@request
|
35
|
+
return @request if @request
|
36
|
+
@request = {query: clause.to_search}
|
37
|
+
@request[:aggs] = clause.get_aggregations if clause.get_aggregations.any?
|
38
|
+
@request
|
26
39
|
end
|
27
40
|
|
28
41
|
def response
|
@@ -32,7 +45,7 @@ module Stretchy
|
|
32
45
|
from: offset,
|
33
46
|
size: limit
|
34
47
|
}
|
35
|
-
params[:explain] = true
|
48
|
+
params[:explain] = true if clause.get_explain
|
36
49
|
@response ||= Stretchy.search(params)
|
37
50
|
end
|
38
51
|
|
@@ -60,6 +73,10 @@ module Stretchy
|
|
60
73
|
end]
|
61
74
|
end
|
62
75
|
|
76
|
+
def aggregations
|
77
|
+
@aggregations ||= response['aggregations']
|
78
|
+
end
|
79
|
+
|
63
80
|
def took
|
64
81
|
@took ||= response['took']
|
65
82
|
end
|
data/lib/stretchy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agius
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|