stretchy 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stretchy/boosts/field_decay_boost.rb +6 -4
- data/lib/stretchy/builders/match_builder.rb +27 -14
- data/lib/stretchy/builders/where_builder.rb +3 -1
- data/lib/stretchy/clauses/base.rb +5 -2
- data/lib/stretchy/clauses/boost_clause.rb +2 -0
- data/lib/stretchy/clauses/boost_match_clause.rb +10 -0
- data/lib/stretchy/clauses/boost_where_clause.rb +10 -2
- data/lib/stretchy/clauses/where_clause.rb +1 -0
- data/lib/stretchy/filters/terms_filter.rb +8 -16
- 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: ea071c20b4f06728acea83eb37c8860235929310
|
4
|
+
data.tar.gz: 288665ba972b8c684e8a48ef1b7fd5d22761864a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b46df2375ccceabc416f34bd71d51f7340d00395b63d2107a030dfc0f5fe951f0b696029ada4101ff3a65ac85210b4c95bbca78452e8d1fc32f944a76dd88f69
|
7
|
+
data.tar.gz: 8df428f03c7bb2b559fca8b1f522ef8e125ebadf830bf3ea7d327edae9b52eb4a7f2b6b092af3dbf75a6133694d8d12653792df0e21cf235212ce31b585cacf1
|
@@ -27,10 +27,12 @@ module Stretchy
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def to_search
|
30
|
-
json = {
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
json = {scale: @scale}
|
31
|
+
if @origin.is_a?(Stretchy::Types::Base)
|
32
|
+
json[:origin] = @origin.to_search
|
33
|
+
else
|
34
|
+
json[:origin] = @origin
|
35
|
+
end
|
34
36
|
json[:offset] = @offset if @offset
|
35
37
|
json[:decay] = @decay if @decay
|
36
38
|
|
@@ -2,13 +2,23 @@ module Stretchy
|
|
2
2
|
module Builders
|
3
3
|
class MatchBuilder
|
4
4
|
|
5
|
-
attr_accessor :matches,
|
5
|
+
attr_accessor :matches, :matchops,
|
6
|
+
:antimatches, :antimatchops,
|
7
|
+
:shouldmatches, :shouldmatchops,
|
8
|
+
:shouldnotmatches, :shouldnotmatchops
|
6
9
|
|
7
10
|
def initialize
|
8
|
-
@matches
|
9
|
-
@
|
10
|
-
|
11
|
-
@
|
11
|
+
@matches = Hash.new { [] }
|
12
|
+
@matchops = Hash.new { 'and' }
|
13
|
+
|
14
|
+
@antimatches = Hash.new { [] }
|
15
|
+
@antimatchops = Hash.new { 'and' }
|
16
|
+
|
17
|
+
@shouldmatches = Hash.new { [] }
|
18
|
+
@shouldmatchops = Hash.new { 'and' }
|
19
|
+
|
20
|
+
@shouldnotmatches = Hash.new { [] }
|
21
|
+
@shouldnotmatchops = Hash.new { 'and' }
|
12
22
|
end
|
13
23
|
|
14
24
|
def any?
|
@@ -23,15 +33,14 @@ module Stretchy
|
|
23
33
|
|
24
34
|
bool_query
|
25
35
|
else
|
26
|
-
|
27
|
-
Stretchy::Queries::MatchQuery.new(field: field, string: strings.join(' '))
|
36
|
+
to_queries(@matches, @matchops).first
|
28
37
|
end
|
29
38
|
end
|
30
39
|
|
31
40
|
def bool_query
|
32
41
|
Stretchy::Queries::BoolQuery.new(
|
33
|
-
must: to_queries(@matches),
|
34
|
-
must_not: to_queries(@antimatches),
|
42
|
+
must: to_queries(@matches, @matchops),
|
43
|
+
must_not: to_queries(@antimatches, @antimatchops),
|
35
44
|
should: build_should
|
36
45
|
)
|
37
46
|
end
|
@@ -39,19 +48,23 @@ module Stretchy
|
|
39
48
|
def build_should
|
40
49
|
if @shouldnotmatches.any?
|
41
50
|
Stretchy::Queries::BoolQuery.new(
|
42
|
-
must: to_queries(@shouldmatches),
|
43
|
-
must_not: to_queries(@shouldnotmatches)
|
51
|
+
must: to_queries(@shouldmatches, @shouldmatchops),
|
52
|
+
must_not: to_queries(@shouldnotmatches, @shouldnotmatchops)
|
44
53
|
)
|
45
54
|
else
|
46
|
-
to_queries(@shouldmatches)
|
55
|
+
to_queries(@shouldmatches, @shouldmatchops)
|
47
56
|
end
|
48
57
|
end
|
49
58
|
|
50
59
|
private
|
51
60
|
|
52
|
-
def to_queries(matches)
|
61
|
+
def to_queries(matches, operators)
|
53
62
|
matches.map do |field, strings|
|
54
|
-
Stretchy::Queries::MatchQuery.new(
|
63
|
+
Stretchy::Queries::MatchQuery.new(
|
64
|
+
field: field,
|
65
|
+
string: strings.join(' '),
|
66
|
+
operator: operators[field]
|
67
|
+
)
|
55
68
|
end
|
56
69
|
end
|
57
70
|
|
@@ -167,7 +167,9 @@ module Stretchy
|
|
167
167
|
near_fields = Hash(options[:near_fields])
|
168
168
|
exists = Array(options[:exists])
|
169
169
|
|
170
|
-
|
170
|
+
terms.each do |field, values|
|
171
|
+
filters << Stretchy::Filters::TermsFilter.new(field, values)
|
172
|
+
end
|
171
173
|
|
172
174
|
filters += exists.map do |field|
|
173
175
|
Stretchy::Filters::ExistsFilter.new(field)
|
@@ -10,7 +10,8 @@ module Stretchy
|
|
10
10
|
attr_accessor :match_builder, :where_builder, :boost_builder,
|
11
11
|
:aggregate_builder, :inverse, :type, :index_name
|
12
12
|
|
13
|
-
delegate [:response, :results, :ids, :hits,
|
13
|
+
delegate [:request, :response, :results, :ids, :hits,
|
14
|
+
:took, :shards, :total, :max_score] => :query_results
|
14
15
|
delegate [:range, :geo] => :where
|
15
16
|
|
16
17
|
def initialize(base_or_opts = nil, options = {})
|
@@ -60,10 +61,12 @@ module Stretchy
|
|
60
61
|
def match(options = {})
|
61
62
|
MatchClause.new(self, options)
|
62
63
|
end
|
64
|
+
alias :fulltext :match
|
63
65
|
|
64
66
|
def where(options = {})
|
65
67
|
WhereClause.new(self, options)
|
66
68
|
end
|
69
|
+
alias :filter :where
|
67
70
|
|
68
71
|
def boost(options = {})
|
69
72
|
BoostClause.new(self, options)
|
@@ -106,7 +109,7 @@ module Stretchy
|
|
106
109
|
end
|
107
110
|
|
108
111
|
def query_results
|
109
|
-
@query_results ||= Stretchy::Results::Base.new(
|
112
|
+
@query_results ||= Stretchy::Results::Base.new(self)
|
110
113
|
end
|
111
114
|
|
112
115
|
end
|
@@ -16,10 +16,12 @@ module Stretchy
|
|
16
16
|
def match(options = {})
|
17
17
|
BoostMatchClause.new(self, options)
|
18
18
|
end
|
19
|
+
alias :fulltext :match
|
19
20
|
|
20
21
|
def where(options = {})
|
21
22
|
BoostWhereClause.new(self, options)
|
22
23
|
end
|
24
|
+
alias :filter :where
|
23
25
|
|
24
26
|
def near(options = {})
|
25
27
|
if options[:lat] || options[:latitude] ||
|
@@ -4,6 +4,8 @@ module Stretchy
|
|
4
4
|
module Clauses
|
5
5
|
class BoostMatchClause < BoostClause
|
6
6
|
|
7
|
+
delegate [:range, :geo] => :where
|
8
|
+
|
7
9
|
def initialize(base, opts_or_string = {}, options = {})
|
8
10
|
super(base)
|
9
11
|
if opts_or_string.is_a?(Hash)
|
@@ -19,6 +21,14 @@ module Stretchy
|
|
19
21
|
self.class.new(self, opts_or_string, options.merge(inverse: !inverse?))
|
20
22
|
end
|
21
23
|
|
24
|
+
def where(*args)
|
25
|
+
WhereClause.new(self, *args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def match(*args)
|
29
|
+
MatchClause.new(self, *args)
|
30
|
+
end
|
31
|
+
|
22
32
|
private
|
23
33
|
|
24
34
|
def match_function(options = {})
|
@@ -10,14 +10,22 @@ module Stretchy
|
|
10
10
|
self
|
11
11
|
end
|
12
12
|
|
13
|
+
def where(*args)
|
14
|
+
WhereClause.new(self, *args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def match(*args)
|
18
|
+
MatchClause.new(self, *args)
|
19
|
+
end
|
20
|
+
|
13
21
|
def range(*args)
|
14
22
|
where_function(:range, *args)
|
15
|
-
self
|
23
|
+
Base.new(self)
|
16
24
|
end
|
17
25
|
|
18
26
|
def geo(*args)
|
19
27
|
where_function(:geo, *args)
|
20
|
-
self
|
28
|
+
Base.new(self)
|
21
29
|
end
|
22
30
|
|
23
31
|
private
|
@@ -112,6 +112,7 @@ module Stretchy
|
|
112
112
|
get_storage(:exists, true) << field
|
113
113
|
when String, Symbol
|
114
114
|
get_storage(:matches)[field] += Array(param)
|
115
|
+
get_storage(:matchops)[field] = 'or'
|
115
116
|
when Range
|
116
117
|
get_storage(:ranges)[field] = Stretchy::Types::Range.new(param)
|
117
118
|
else
|
@@ -5,27 +5,19 @@ module Stretchy
|
|
5
5
|
class TermsFilter < Base
|
6
6
|
|
7
7
|
contract field: {type: :field, required: true},
|
8
|
-
|
8
|
+
terms: {type: [Numeric, Time, String, Symbol], array: true, required: true}
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@terms = { field_or_opts => Array(terms) }
|
15
|
-
end
|
16
|
-
validate_terms!
|
17
|
-
end
|
18
|
-
|
19
|
-
def validate_terms!
|
20
|
-
exc = Stretchy::Errors::ContractError.new("Terms cannot be blank")
|
21
|
-
raise exc if @terms.none? || @terms.any? do |field, terms|
|
22
|
-
terms.none?
|
23
|
-
end
|
10
|
+
def initialize(field, terms)
|
11
|
+
@field = field
|
12
|
+
@terms = Array(terms)
|
13
|
+
validate!
|
24
14
|
end
|
25
15
|
|
26
16
|
def to_search
|
27
17
|
{
|
28
|
-
terms:
|
18
|
+
terms: {
|
19
|
+
@field => @terms
|
20
|
+
}
|
29
21
|
}
|
30
22
|
end
|
31
23
|
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.2
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|