arelastic 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/arelastic/builders/mapping.rb +16 -0
- data/lib/arelastic/builders/sort.rb +4 -4
- data/lib/arelastic/builders.rb +1 -0
- data/lib/arelastic/mappings/type.rb +14 -4
- data/lib/arelastic/mappings/types/multi_field.rb +15 -9
- data/lib/arelastic/mappings/types/string.rb +1 -0
- data/lib/arelastic/searches/sort.rb +8 -1
- data/lib/arelastic/sorts/asc.rb +0 -0
- data/lib/arelastic/sorts/sort.rb +53 -0
- data/lib/arelastic/sorts.rb +1 -0
- data/lib/arelastic.rb +1 -0
- data/test/arelastic/arities/binary_test.rb +1 -1
- data/test/arelastic/arities/polyadic_test.rb +1 -1
- data/test/arelastic/arities/unary_test.rb +1 -1
- data/test/arelastic/builders/filter_test.rb +1 -1
- data/test/arelastic/builders/mapping_test.rb +4 -0
- data/test/arelastic/builders/query_test.rb +1 -1
- data/test/arelastic/builders/search_test.rb +1 -1
- data/test/arelastic/builders/sort_test.rb +1 -1
- data/test/arelastic/facets/histogram_test.rb +1 -1
- data/test/arelastic/facets/terms_test.rb +1 -1
- data/test/arelastic/filters/exists_test.rb +1 -1
- data/test/arelastic/filters/filter_test.rb +1 -1
- data/test/arelastic/filters/geo_distance_test.rb +1 -1
- data/test/arelastic/filters/has_child_test.rb +1 -1
- data/test/arelastic/filters/ids_test.rb +1 -1
- data/test/arelastic/filters/match_all_test.rb +1 -1
- data/test/arelastic/filters/missing_test.rb +1 -1
- data/test/arelastic/filters/not_test.rb +1 -1
- data/test/arelastic/filters/query_test.rb +1 -1
- data/test/arelastic/mappings/types/binary_test.rb +10 -0
- data/test/arelastic/mappings/types/multi_field_test.rb +18 -0
- data/test/arelastic/mappings/types/string_test.rb +10 -0
- data/test/arelastic/nodes/node_test.rb +1 -1
- data/test/arelastic/queries/filtered_test.rb +1 -1
- data/test/arelastic/queries/match_all_test.rb +1 -1
- data/test/arelastic/queries/query_string_test.rb +1 -1
- data/test/arelastic/queries/query_test.rb +1 -1
- data/test/arelastic/searches/sort_test.rb +13 -0
- data/test/arelastic/sorts/sort_test.rb +47 -0
- metadata +17 -9
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6cf678c64069a5d89e411132f83ac62f3d009dab
|
4
|
+
data.tar.gz: 27fd293a467d708af530101687f79d75d8866941
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e94367a5bbbf4b119cb32a6db103899f17c162062ebe5cc9ce89d5557d4bec0e9cac6f22fb077b6fbc4a51f0ecb26f510f8c37361d47961da7dff538ef97868a
|
7
|
+
data.tar.gz: e60d85515dac401c2fdb45ceb4d71875873f5404209d0bbd611c09427f745e99390eec4f4b0fb1511c2e7dddfcc69dcbd18578359d0b24718705b3f37de14879
|
@@ -7,12 +7,12 @@ module Arelastic
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def asc
|
11
|
-
|
10
|
+
def asc(options = nil)
|
11
|
+
Arelastic::Sorts::Sort.new(field => 'asc', options)
|
12
12
|
end
|
13
13
|
|
14
|
-
def desc
|
15
|
-
|
14
|
+
def desc(options = nil)
|
15
|
+
Arelastic::Sorts::Sort.new(field => 'asc', options)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/arelastic/builders.rb
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Mappings
|
3
3
|
class Type < Arelastic::Nodes::Node
|
4
|
-
|
4
|
+
class << self
|
5
|
+
attr_reader :type
|
6
|
+
def for_type(type)
|
7
|
+
@type = type
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :field, :options
|
12
|
+
def initialize(field, options = {})
|
13
|
+
@field = field
|
14
|
+
@options = options
|
5
15
|
end
|
6
16
|
|
7
17
|
def as_elastic
|
8
|
-
{
|
9
|
-
|
10
|
-
}
|
18
|
+
params = {'type' => self.class.type}.update(options)
|
19
|
+
|
20
|
+
{ field => params }
|
11
21
|
end
|
12
22
|
end
|
13
23
|
end
|
@@ -1,14 +1,20 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Mappings
|
3
3
|
class MultiField < Arelastic::Mappings::Type
|
4
|
-
|
4
|
+
attr_reader :field, :field_mappings
|
5
|
+
def initialize(field, field_mappings)
|
6
|
+
@field = field
|
7
|
+
@field_mappings = field_mappings
|
8
|
+
end
|
9
|
+
|
10
|
+
def as_elastic
|
11
|
+
{
|
12
|
+
field => {
|
13
|
+
'type' => 'multi_field',
|
14
|
+
'fields' => field_mappings
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
5
18
|
end
|
6
19
|
end
|
7
|
-
end
|
8
|
-
# "name" : {
|
9
|
-
# "type" : "multi_field",
|
10
|
-
# "fields" : {
|
11
|
-
# "name" : {"type" : "string", "index" : "analyzed"},
|
12
|
-
# "untouched" : {"type" : "string", "index" : "not_analyzed"}
|
13
|
-
# }
|
14
|
-
# }
|
20
|
+
end
|
@@ -1,7 +1,14 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Searches
|
3
3
|
class Sort < Arelastic::Searches::Search
|
4
|
-
|
4
|
+
attr_reader :sorts
|
5
|
+
def initialize sorts
|
6
|
+
@sorts = sorts
|
7
|
+
end
|
8
|
+
|
9
|
+
def as_elastic
|
10
|
+
{'sort' => sorts.map { |sort| convert_to_elastic(sort) }}
|
11
|
+
end
|
5
12
|
end
|
6
13
|
end
|
7
14
|
end
|
File without changes
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Sorts
|
3
|
+
class Sort < Arelastic::Nodes::Node
|
4
|
+
attr_reader :field, :options
|
5
|
+
|
6
|
+
# Sort.new('price').as_elastic
|
7
|
+
# => 'price'
|
8
|
+
#
|
9
|
+
# Sort.new('price' => 'asc').as_elastic
|
10
|
+
# => {'price' => 'asc'}
|
11
|
+
#
|
12
|
+
# Sort.new('price', 'order' => 'asc').as_elastic
|
13
|
+
# => {'price' => {'order', 'asc'}}
|
14
|
+
#
|
15
|
+
# Sort.new({'price' => 'asc'}, {'missing' => '_last'}).as_elastic
|
16
|
+
# => {'price' => {'order' => 'asc', 'missing' => '_last'}}
|
17
|
+
#
|
18
|
+
def initialize(field, extra_options = nil)
|
19
|
+
if field.is_a?(Hash)
|
20
|
+
@field, @options = field.first.to_a
|
21
|
+
if extra_options
|
22
|
+
@options = (@options.is_a?(Hash) ? @options : {'order' => @options}).update(extra_options)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
@field = field
|
26
|
+
@options = extra_options
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def reverse
|
31
|
+
reverse_order = ordering == 'desc' ? 'asc' : 'desc'
|
32
|
+
|
33
|
+
if options.is_a?(Hash)
|
34
|
+
Arelastic::Sorts::Sort.new(field, options.merge('order' => reverse_order))
|
35
|
+
else
|
36
|
+
Arelastic::Sorts::Sort.new(field => reverse_order)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def ordering
|
41
|
+
(options.is_a?(Hash) ? options['order'] : options).to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def as_elastic
|
45
|
+
if options
|
46
|
+
{field => options}
|
47
|
+
else
|
48
|
+
field
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arelastic/sorts/sort'
|
data/lib/arelastic.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::Builders::FilterTest < MiniTest::
|
3
|
+
class Arelastic::Builders::FilterTest < MiniTest::Unit::TestCase
|
4
4
|
def test_ids
|
5
5
|
expected = {"ids" => {"values"=>["5", "6"]}}
|
6
6
|
assert_equal expected, Arelastic::Builders::Filter.ids('5', '6').as_elastic
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::Builders::QueryTest < MiniTest::
|
3
|
+
class Arelastic::Builders::QueryTest < MiniTest::Unit::TestCase
|
4
4
|
def test_constant_score
|
5
5
|
query = Arelastic::Builders::Query.constant_score({"foo" => "bar"})
|
6
6
|
expected = {"query" => {"constant_score" => {"foo" => "bar"}}}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::Facets::TermsTest < MiniTest::
|
3
|
+
class Arelastic::Facets::TermsTest < MiniTest::Unit::TestCase
|
4
4
|
def test_as_elastic
|
5
5
|
facet = Arelastic::Facets::Histogram.new('histo', "field" => "field_name", "interval" => 100)
|
6
6
|
expected = {
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Mappings::BinaryTest < MiniTest::Unit::TestCase
|
4
|
+
def test_as_elastic
|
5
|
+
type = Arelastic::Mappings::Binary.new('message', 'index' => 'analyzed')
|
6
|
+
expected = {'message' => {'type' => 'binary', 'index' => 'analyzed'}}
|
7
|
+
|
8
|
+
assert_equal expected, type.as_elastic
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Mappings::MultiFieldTest < MiniTest::Unit::TestCase
|
4
|
+
def test_as_elastic
|
5
|
+
type = Arelastic::Mappings::MultiField.new('message', 'message' => {'type' => 'string', 'index' => 'analyzed'}, 'untouched' => {'type' => 'string', 'index' => 'not_analyzed'})
|
6
|
+
expected = {
|
7
|
+
'message' => {
|
8
|
+
'type' => 'multi_field',
|
9
|
+
'fields' => {
|
10
|
+
'message' => {'type' => 'string', 'index' => 'analyzed'},
|
11
|
+
'untouched' => {'type' => 'string', 'index' => 'not_analyzed'}
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
assert_equal expected, type.as_elastic
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Mappings::StringTest < MiniTest::Unit::TestCase
|
4
|
+
def test_as_elastic
|
5
|
+
type = Arelastic::Mappings::String.new('message', 'index' => 'analyzed')
|
6
|
+
expected = {'message' => {'type' => 'string', 'index' => 'analyzed'}}
|
7
|
+
|
8
|
+
assert_equal expected, type.as_elastic
|
9
|
+
end
|
10
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::Queries::FilteredTest < MiniTest::
|
3
|
+
class Arelastic::Queries::FilteredTest < MiniTest::Unit::TestCase
|
4
4
|
def test_as_elastic
|
5
5
|
filtered = Arelastic::Queries::Filtered.new({"query_string" => "bar"}, {"term" => "baz"})
|
6
6
|
expected = {"filtered" => {"query" => {"query_string" => "bar"}, "filter" => {"term" => "baz"}}}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class Arelastic::Queries::QueryStringTest < MiniTest::
|
3
|
+
class Arelastic::Queries::QueryStringTest < MiniTest::Unit::TestCase
|
4
4
|
def test_as_elastic
|
5
5
|
query_string = Arelastic::Queries::QueryString.new('foo')
|
6
6
|
expected = {"query_string" => {"query" => "foo"}}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Searches::SortTest < MiniTest::Spec
|
4
|
+
def test_as_elastic
|
5
|
+
sort = Arelastic::Searches::Sort.new [
|
6
|
+
Arelastic::Sorts::Sort.new('price'),
|
7
|
+
{'name' => 'asc'}
|
8
|
+
]
|
9
|
+
expected = {'sort' => ['price', {'name' => 'asc'}]}
|
10
|
+
|
11
|
+
assert_equal expected, sort.as_elastic
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Sorts::SortTest < MiniTest::Spec
|
4
|
+
def test_as_elastic
|
5
|
+
assert_equal(
|
6
|
+
'price',
|
7
|
+
Arelastic::Sorts::Sort.new('price').as_elastic,
|
8
|
+
)
|
9
|
+
|
10
|
+
assert_equal(
|
11
|
+
{'price' => 'asc'},
|
12
|
+
Arelastic::Sorts::Sort.new('price' => 'asc').as_elastic
|
13
|
+
)
|
14
|
+
|
15
|
+
assert_equal(
|
16
|
+
{'price' => {'order' => 'asc'}},
|
17
|
+
Arelastic::Sorts::Sort.new('price', 'order' => 'asc').as_elastic
|
18
|
+
)
|
19
|
+
|
20
|
+
assert_equal(
|
21
|
+
{'price' => {'order' => 'asc', 'missing' => '_last'}},
|
22
|
+
Arelastic::Sorts::Sort.new({'price' => 'asc'}, {'missing' => '_last'}).as_elastic
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_reverse
|
27
|
+
assert_equal(
|
28
|
+
{'price' => 'desc'},
|
29
|
+
Arelastic::Sorts::Sort.new('price').reverse.as_elastic,
|
30
|
+
)
|
31
|
+
|
32
|
+
assert_equal(
|
33
|
+
{'price' => 'desc'},
|
34
|
+
Arelastic::Sorts::Sort.new('price' => 'asc').reverse.as_elastic
|
35
|
+
)
|
36
|
+
|
37
|
+
assert_equal(
|
38
|
+
{'price' => 'asc'},
|
39
|
+
Arelastic::Sorts::Sort.new('price' => 'desc').reverse.as_elastic
|
40
|
+
)
|
41
|
+
|
42
|
+
assert_equal(
|
43
|
+
{'price' => {'order' => 'asc', 'missing' => '_last'}},
|
44
|
+
Arelastic::Sorts::Sort.new({'price' => 'desc'}, {'missing' => '_last'}).reverse.as_elastic
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arelastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Matthew Higgins
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Build Elastic Search queries with objects
|
15
14
|
email: developer@matthewhiggins.com
|
@@ -24,6 +23,7 @@ files:
|
|
24
23
|
- lib/arelastic/arities.rb
|
25
24
|
- lib/arelastic/builders/facet.rb
|
26
25
|
- lib/arelastic/builders/filter.rb
|
26
|
+
- lib/arelastic/builders/mapping.rb
|
27
27
|
- lib/arelastic/builders/query.rb
|
28
28
|
- lib/arelastic/builders/search.rb
|
29
29
|
- lib/arelastic/builders/sort.rb
|
@@ -82,11 +82,15 @@ files:
|
|
82
82
|
- lib/arelastic/searches/size.rb
|
83
83
|
- lib/arelastic/searches/sort.rb
|
84
84
|
- lib/arelastic/searches.rb
|
85
|
+
- lib/arelastic/sorts/asc.rb
|
86
|
+
- lib/arelastic/sorts/sort.rb
|
87
|
+
- lib/arelastic/sorts.rb
|
85
88
|
- lib/arelastic.rb
|
86
89
|
- test/arelastic/arities/binary_test.rb
|
87
90
|
- test/arelastic/arities/polyadic_test.rb
|
88
91
|
- test/arelastic/arities/unary_test.rb
|
89
92
|
- test/arelastic/builders/filter_test.rb
|
93
|
+
- test/arelastic/builders/mapping_test.rb
|
90
94
|
- test/arelastic/builders/query_test.rb
|
91
95
|
- test/arelastic/builders/search_test.rb
|
92
96
|
- test/arelastic/builders/sort_test.rb
|
@@ -102,36 +106,40 @@ files:
|
|
102
106
|
- test/arelastic/filters/missing_test.rb
|
103
107
|
- test/arelastic/filters/not_test.rb
|
104
108
|
- test/arelastic/filters/query_test.rb
|
109
|
+
- test/arelastic/mappings/types/binary_test.rb
|
110
|
+
- test/arelastic/mappings/types/multi_field_test.rb
|
111
|
+
- test/arelastic/mappings/types/string_test.rb
|
105
112
|
- test/arelastic/nodes/node_test.rb
|
106
113
|
- test/arelastic/queries/filtered_test.rb
|
107
114
|
- test/arelastic/queries/match_all_test.rb
|
108
115
|
- test/arelastic/queries/query_string_test.rb
|
109
116
|
- test/arelastic/queries/query_test.rb
|
117
|
+
- test/arelastic/searches/sort_test.rb
|
118
|
+
- test/arelastic/sorts/sort_test.rb
|
110
119
|
- test/helper.rb
|
111
120
|
- README.rdoc
|
112
121
|
homepage: http://github.com/matthuhiggins/arelastic
|
113
122
|
licenses:
|
114
123
|
- MIT
|
124
|
+
metadata: {}
|
115
125
|
post_install_message:
|
116
126
|
rdoc_options: []
|
117
127
|
require_paths:
|
118
128
|
- lib
|
119
129
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
130
|
requirements:
|
121
|
-
- -
|
131
|
+
- - '>='
|
122
132
|
- !ruby/object:Gem::Version
|
123
133
|
version: 1.9.3
|
124
|
-
none: false
|
125
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
135
|
requirements:
|
127
|
-
- -
|
136
|
+
- - '>='
|
128
137
|
- !ruby/object:Gem::Version
|
129
138
|
version: 1.8.11
|
130
|
-
none: false
|
131
139
|
requirements: []
|
132
140
|
rubyforge_project:
|
133
|
-
rubygems_version:
|
141
|
+
rubygems_version: 2.0.0
|
134
142
|
signing_key:
|
135
|
-
specification_version:
|
143
|
+
specification_version: 4
|
136
144
|
summary: Elastic Search query builder
|
137
145
|
test_files: []
|