arelastic 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -1
- data/lib/arelastic/arities/binary.rb +6 -7
- data/lib/arelastic/builders/query.rb +9 -0
- data/lib/arelastic/builders/sort.rb +4 -0
- data/lib/arelastic/filters/terms.rb +1 -12
- data/lib/arelastic/queries.rb +2 -0
- data/lib/arelastic/queries/match.rb +7 -0
- data/lib/arelastic/queries/multi_match.rb +6 -0
- data/test/arelastic/arities/binary_test.rb +3 -0
- data/test/arelastic/builders/query_test.rb +12 -1
- metadata +4 -2
data/README.rdoc
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
=
|
1
|
+
= Arelastic
|
2
2
|
{<img src="https://secure.travis-ci.org/matthuhiggins/arelastic.png?rvm=1.9.3" />}[http://travis-ci.org/matthuhiggins/arelastic]
|
@@ -9,21 +9,20 @@ module Arelastic
|
|
9
9
|
attr_reader :predicate
|
10
10
|
end
|
11
11
|
|
12
|
-
attr_reader :field, :value
|
12
|
+
attr_reader :field, :value, :options
|
13
13
|
end
|
14
14
|
|
15
15
|
module Methods
|
16
|
-
def initialize field, value
|
16
|
+
def initialize field, value, options = {}
|
17
17
|
@field = field
|
18
18
|
@value = value
|
19
|
+
@options = options
|
19
20
|
end
|
20
21
|
|
21
22
|
def as_elastic
|
22
|
-
{
|
23
|
-
|
24
|
-
|
25
|
-
}
|
26
|
-
}
|
23
|
+
params = {field => convert_to_elastic(value)}.update(options)
|
24
|
+
|
25
|
+
{ self.class.predicate => params }
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
@@ -5,6 +5,7 @@ module Arelastic
|
|
5
5
|
def [](field)
|
6
6
|
new(field)
|
7
7
|
end
|
8
|
+
|
8
9
|
def constant_score(filter_or_query)
|
9
10
|
query Arelastic::Queries::ConstantScore.new(filter_or_query)
|
10
11
|
end
|
@@ -17,6 +18,10 @@ module Arelastic
|
|
17
18
|
query Arelastic::Queries::MatchAll.new
|
18
19
|
end
|
19
20
|
|
21
|
+
def multi_match other, fields
|
22
|
+
# Arelastic::Queries::MultiMatch.new other, fields
|
23
|
+
end
|
24
|
+
|
20
25
|
private
|
21
26
|
def query value
|
22
27
|
Arelastic::Searches::Query.new value
|
@@ -34,6 +39,10 @@ module Arelastic
|
|
34
39
|
def terms other
|
35
40
|
Arelastic::Queries::Terms.new name, other
|
36
41
|
end
|
42
|
+
|
43
|
+
def match other
|
44
|
+
Arelastic::Queries::Match.new name, other
|
45
|
+
end
|
37
46
|
end
|
38
47
|
end
|
39
48
|
end
|
@@ -1,18 +1,7 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Filters
|
3
3
|
class Terms < Arelastic::Filters::Filter
|
4
|
-
|
5
|
-
def initialize(field, terms, options = {})
|
6
|
-
@field = field
|
7
|
-
@terms = terms
|
8
|
-
@options = options
|
9
|
-
end
|
10
|
-
|
11
|
-
def as_elastic
|
12
|
-
params = {field => terms}.update(options)
|
13
|
-
|
14
|
-
{ "terms" => params }
|
15
|
-
end
|
4
|
+
binary 'terms'
|
16
5
|
end
|
17
6
|
end
|
18
7
|
end
|
data/lib/arelastic/queries.rb
CHANGED
@@ -3,7 +3,9 @@ require 'arelastic/queries/query'
|
|
3
3
|
require 'arelastic/queries/constant_score'
|
4
4
|
require 'arelastic/queries/field'
|
5
5
|
require 'arelastic/queries/filtered'
|
6
|
+
require 'arelastic/queries/match'
|
6
7
|
require 'arelastic/queries/match_all'
|
8
|
+
require 'arelastic/queries/multi_match'
|
7
9
|
require 'arelastic/queries/prefix'
|
8
10
|
require 'arelastic/queries/query_string'
|
9
11
|
require 'arelastic/queries/terms'
|
@@ -8,5 +8,8 @@ class Arelastic::Arities::BinaryTest < MiniTest::Spec
|
|
8
8
|
|
9
9
|
expected = {'suffix' => {'phone' => '666'}}
|
10
10
|
assert_equal expected, node.new('phone', '666').as_elastic
|
11
|
+
|
12
|
+
expected = {'suffix' => {'phone' => '666', '_cache' => false}}
|
13
|
+
assert_equal expected, node.new('phone', '666', '_cache' => false).as_elastic
|
11
14
|
end
|
12
15
|
end
|
@@ -22,6 +22,10 @@ class Arelastic::Builders::QueryTest < MiniTest::Spec
|
|
22
22
|
assert_equal expected, query.as_elastic
|
23
23
|
end
|
24
24
|
|
25
|
+
def test_multi_match
|
26
|
+
Arelastic::Builders::Query.multi_match 'blue', ['color', 'description']
|
27
|
+
end
|
28
|
+
|
25
29
|
def test_field
|
26
30
|
query = Arelastic::Builders::Query['user'].field 'kimchy'
|
27
31
|
expected = { "field" => { "user" => "kimchy" } }
|
@@ -36,10 +40,17 @@ class Arelastic::Builders::QueryTest < MiniTest::Spec
|
|
36
40
|
assert_equal expected, query.as_elastic
|
37
41
|
end
|
38
42
|
|
39
|
-
def
|
43
|
+
def test_terms
|
40
44
|
query = Arelastic::Builders::Query['tags'].terms ['blue', 'pill']
|
41
45
|
expected = {"terms" => { "tags" => ["blue", "pill"] }}
|
42
46
|
|
43
47
|
assert_equal expected, query.as_elastic
|
44
48
|
end
|
49
|
+
|
50
|
+
def test_match
|
51
|
+
query = Arelastic::Builders::Query['message'].match "hello"
|
52
|
+
expected = {"match" => { "message" => "hello" }}
|
53
|
+
|
54
|
+
assert_equal expected, query.as_elastic
|
55
|
+
end
|
45
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arelastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Build Elastic Search queries with objects
|
15
15
|
email: developer@matthewhiggins.com
|
@@ -53,7 +53,9 @@ files:
|
|
53
53
|
- lib/arelastic/queries/constant_score.rb
|
54
54
|
- lib/arelastic/queries/field.rb
|
55
55
|
- lib/arelastic/queries/filtered.rb
|
56
|
+
- lib/arelastic/queries/match.rb
|
56
57
|
- lib/arelastic/queries/match_all.rb
|
58
|
+
- lib/arelastic/queries/multi_match.rb
|
57
59
|
- lib/arelastic/queries/prefix.rb
|
58
60
|
- lib/arelastic/queries/query.rb
|
59
61
|
- lib/arelastic/queries/query_string.rb
|