arelastic 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +0 -0
- data/lib/arelastic/arities/binary.rb +31 -0
- data/lib/arelastic/arities/polyadic.rb +26 -0
- data/lib/arelastic/arities/unary.rb +27 -0
- data/lib/arelastic/arities.rb +3 -0
- data/lib/arelastic/builders/facet.rb +19 -0
- data/lib/arelastic/builders/filter.rb +77 -0
- data/lib/arelastic/builders/query.rb +39 -0
- data/lib/arelastic/builders/search.rb +25 -0
- data/lib/arelastic/builders/sort.rb +15 -0
- data/lib/arelastic/builders.rb +4 -0
- data/lib/arelastic/facets/facet.rb +6 -0
- data/lib/arelastic/facets/histogram.rb +19 -0
- data/lib/arelastic/facets/range.rb +0 -0
- data/lib/arelastic/facets/terms.rb +22 -0
- data/lib/arelastic/facets.rb +5 -0
- data/lib/arelastic/filters/and.rb +7 -0
- data/lib/arelastic/filters/exists.rb +15 -0
- data/lib/arelastic/filters/filter.rb +17 -0
- data/lib/arelastic/filters/ids.rb +16 -0
- data/lib/arelastic/filters/limit.rb +15 -0
- data/lib/arelastic/filters/missing.rb +20 -0
- data/lib/arelastic/filters/not.rb +15 -0
- data/lib/arelastic/filters/or.rb +7 -0
- data/lib/arelastic/filters/prefix.rb +7 -0
- data/lib/arelastic/filters/range.rb +7 -0
- data/lib/arelastic/filters/term.rb +7 -0
- data/lib/arelastic/filters/terms.rb +7 -0
- data/lib/arelastic/filters.rb +13 -0
- data/lib/arelastic/nodes/hash_group.rb +18 -0
- data/lib/arelastic/nodes/node.rb +17 -0
- data/lib/arelastic/nodes.rb +2 -0
- data/lib/arelastic/queries/constant_score.rb +7 -0
- data/lib/arelastic/queries/field.rb +7 -0
- data/lib/arelastic/queries/filtered.rb +15 -0
- data/lib/arelastic/queries/match_all.rb +9 -0
- data/lib/arelastic/queries/prefix.rb +7 -0
- data/lib/arelastic/queries/query.rb +6 -0
- data/lib/arelastic/queries/query_string.rb +17 -0
- data/lib/arelastic/queries/term.rb +7 -0
- data/lib/arelastic/queries/terms.rb +7 -0
- data/lib/arelastic/queries.rb +10 -0
- data/lib/arelastic/searches/facets.rb +14 -0
- data/lib/arelastic/searches/filter.rb +7 -0
- data/lib/arelastic/searches/from.rb +7 -0
- data/lib/arelastic/searches/query.rb +7 -0
- data/lib/arelastic/searches/search.rb +6 -0
- data/lib/arelastic/searches/size.rb +7 -0
- data/lib/arelastic/searches/sort.rb +7 -0
- data/lib/arelastic/searches.rb +8 -0
- data/lib/arelastic.rb +8 -0
- data/test/arelastic/arities/binary_test.rb +12 -0
- data/test/arelastic/arities/polyadic_test.rb +13 -0
- data/test/arelastic/arities/unary_test.rb +12 -0
- data/test/arelastic/builders/filter_test.rb +56 -0
- data/test/arelastic/builders/query_test.rb +45 -0
- data/test/arelastic/builders/search_test.rb +4 -0
- data/test/arelastic/builders/sort_test.rb +5 -0
- data/test/arelastic/facets/histogram_test.rb +17 -0
- data/test/arelastic/facets/terms_test.rb +17 -0
- data/test/arelastic/filters/exists_test.rb +9 -0
- data/test/arelastic/filters/filter_test.rb +30 -0
- data/test/arelastic/filters/ids_test.rb +9 -0
- data/test/arelastic/filters/missing_test.rb +15 -0
- data/test/arelastic/filters/not_test.rb +9 -0
- data/test/arelastic/nodes/node_test.rb +18 -0
- data/test/arelastic/queries/filtered_test.rb +10 -0
- data/test/arelastic/queries/match_all_test.rb +10 -0
- data/test/arelastic/queries/query_string_test.rb +10 -0
- data/test/arelastic/queries/query_test.rb +5 -0
- data/test/helper.rb +4 -0
- metadata +117 -0
data/README.rdoc
ADDED
File without changes
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Arities
|
3
|
+
module Binary
|
4
|
+
def binary(predicate)
|
5
|
+
@predicate = predicate
|
6
|
+
include Methods
|
7
|
+
|
8
|
+
singleton_class.class_eval do
|
9
|
+
attr_reader :predicate
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :field, :value
|
13
|
+
end
|
14
|
+
|
15
|
+
module Methods
|
16
|
+
def initialize field, value
|
17
|
+
@field = field
|
18
|
+
@value = value
|
19
|
+
end
|
20
|
+
|
21
|
+
def as_elastic
|
22
|
+
{
|
23
|
+
self.class.predicate => {
|
24
|
+
field => convert_to_elastic(value)
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Arities
|
3
|
+
module Polyadic
|
4
|
+
def polyadic(operator)
|
5
|
+
@operator = operator
|
6
|
+
include Methods
|
7
|
+
|
8
|
+
singleton_class.class_eval do
|
9
|
+
attr_reader :operator
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :children
|
13
|
+
end
|
14
|
+
|
15
|
+
module Methods
|
16
|
+
def initialize children
|
17
|
+
@children = children
|
18
|
+
end
|
19
|
+
|
20
|
+
def as_elastic
|
21
|
+
{self.class.operator => children.map { |child| convert_to_elastic(child) }}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Arities
|
3
|
+
module Unary
|
4
|
+
def unary(field, options = {})
|
5
|
+
@field = field
|
6
|
+
include Methods
|
7
|
+
|
8
|
+
singleton_class.class_eval do
|
9
|
+
attr_reader :field
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :expr
|
13
|
+
end
|
14
|
+
|
15
|
+
module Methods
|
16
|
+
def initialize expr
|
17
|
+
# raise "#{expr.inspect} must be an Arelastic::Filters::Filter" unless expr.is_a?(Arelastic::Filters::Filter)
|
18
|
+
@expr = expr
|
19
|
+
end
|
20
|
+
|
21
|
+
def as_elastic
|
22
|
+
{self.class.field => convert_to_elastic(expr)}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Builders
|
3
|
+
class Facet < Struct.new :name
|
4
|
+
class << self
|
5
|
+
def [](name)
|
6
|
+
new(name)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def terms field, options = {}
|
11
|
+
Arelastic::Facets::Terms.new name, field, options
|
12
|
+
end
|
13
|
+
|
14
|
+
def histogram options
|
15
|
+
Arelastic::Facets::Histogram.new name, options
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Builders
|
3
|
+
class Filter < Struct.new :field
|
4
|
+
class << self
|
5
|
+
def [](field)
|
6
|
+
new(field)
|
7
|
+
end
|
8
|
+
|
9
|
+
def ids *ids
|
10
|
+
Arelastic::Filters::Ids.new ids.flatten
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def eq other
|
15
|
+
Arelastic::Filters::Term.new field, other
|
16
|
+
end
|
17
|
+
|
18
|
+
def not_eq other
|
19
|
+
self.not eq(other)
|
20
|
+
end
|
21
|
+
|
22
|
+
def in other
|
23
|
+
case other
|
24
|
+
when Range
|
25
|
+
if other.exclude_end?
|
26
|
+
range 'gte' => other.begin, 'lt' => other.end
|
27
|
+
else
|
28
|
+
range 'gte' => other.begin, 'lte' => other.end
|
29
|
+
end
|
30
|
+
else
|
31
|
+
Arelastic::Filters::Terms.new field, other
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def not_in other
|
36
|
+
self.not self.in(other)
|
37
|
+
end
|
38
|
+
|
39
|
+
def prefix other
|
40
|
+
Arelastic::Filters::Prefix.new field, other
|
41
|
+
end
|
42
|
+
|
43
|
+
def exists
|
44
|
+
Arelastic::Filters::Exists.new field
|
45
|
+
end
|
46
|
+
|
47
|
+
def missing(options = {})
|
48
|
+
Arelastic::Filters::Missing.new field, options
|
49
|
+
end
|
50
|
+
|
51
|
+
def gteq other
|
52
|
+
range 'gte' => other
|
53
|
+
end
|
54
|
+
|
55
|
+
def gt other
|
56
|
+
range 'gt' => other
|
57
|
+
end
|
58
|
+
|
59
|
+
def lteq other
|
60
|
+
range 'lte' => other
|
61
|
+
end
|
62
|
+
|
63
|
+
def lt other
|
64
|
+
range 'lt' => other
|
65
|
+
end
|
66
|
+
|
67
|
+
def not other
|
68
|
+
Arelastic::Filters::Not.new other
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def range options
|
73
|
+
Arelastic::Filters::Range.new field, options
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Builders
|
3
|
+
class Query < Struct.new :name
|
4
|
+
class << self
|
5
|
+
def [](field)
|
6
|
+
new(field)
|
7
|
+
end
|
8
|
+
def constant_score(filter_or_query)
|
9
|
+
query Arelastic::Queries::ConstantScore.new(filter_or_query)
|
10
|
+
end
|
11
|
+
|
12
|
+
def filtered(query, filter)
|
13
|
+
query Arelastic::Queries::Filtered.new(query, filter)
|
14
|
+
end
|
15
|
+
|
16
|
+
def match_all
|
17
|
+
query Arelastic::Queries::MatchAll.new
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def query value
|
22
|
+
Arelastic::Searches::Query.new value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def field other
|
27
|
+
Arelastic::Queries::Field.new name, other
|
28
|
+
end
|
29
|
+
|
30
|
+
def term other
|
31
|
+
Arelastic::Queries::Term.new name, other
|
32
|
+
end
|
33
|
+
|
34
|
+
def terms other
|
35
|
+
Arelastic::Queries::Terms.new name, other
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Builders
|
3
|
+
class Search
|
4
|
+
def filter
|
5
|
+
Arelastic::Builders::Filter
|
6
|
+
end
|
7
|
+
|
8
|
+
def [](field)
|
9
|
+
filter[field]
|
10
|
+
end
|
11
|
+
|
12
|
+
def facet
|
13
|
+
Arelastic::Builders::Facet
|
14
|
+
end
|
15
|
+
|
16
|
+
def query
|
17
|
+
Arelastic::Builders::Query
|
18
|
+
end
|
19
|
+
|
20
|
+
def sort
|
21
|
+
Arelastic::Builders::Sort
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Facets
|
3
|
+
class Histogram < Arelastic::Facets::Facet
|
4
|
+
attr_accessor :name, :options
|
5
|
+
def initialize name, options
|
6
|
+
@name = name
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def as_elastic
|
11
|
+
{
|
12
|
+
name => {
|
13
|
+
"histogram" => options
|
14
|
+
}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Facets
|
3
|
+
class Terms < Arelastic::Facets::Facet
|
4
|
+
attr_accessor :name, :field, :options
|
5
|
+
def initialize name, field, options = {}
|
6
|
+
@name = name
|
7
|
+
@field = field
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_elastic
|
12
|
+
params = {"field" => field}.update(options)
|
13
|
+
|
14
|
+
{
|
15
|
+
name => {
|
16
|
+
"terms" => params
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Filters
|
3
|
+
class Filter < Arelastic::Nodes::Node
|
4
|
+
def or other
|
5
|
+
Arelastic::Filters::Or.new [self, other]
|
6
|
+
end
|
7
|
+
|
8
|
+
def and other
|
9
|
+
Arelastic::Filters::And.new [self, other]
|
10
|
+
end
|
11
|
+
|
12
|
+
def negate
|
13
|
+
Arelastic::Filters::Not.new self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Filters
|
3
|
+
class Missing < Arelastic::Filters::Filter
|
4
|
+
attr_reader :field, :options
|
5
|
+
|
6
|
+
# Options:
|
7
|
+
# "existence" => true defaults to true
|
8
|
+
# "null_value" => true defaults to false
|
9
|
+
def initialize field, options = {}
|
10
|
+
@field = field
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def as_elastic
|
15
|
+
params = {"field" => field}.update(options)
|
16
|
+
{"missing" => params}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'arelastic/filters/filter'
|
2
|
+
|
3
|
+
require 'arelastic/filters/and'
|
4
|
+
require 'arelastic/filters/exists'
|
5
|
+
require 'arelastic/filters/ids'
|
6
|
+
require 'arelastic/filters/limit'
|
7
|
+
require 'arelastic/filters/missing'
|
8
|
+
require 'arelastic/filters/not'
|
9
|
+
require 'arelastic/filters/or'
|
10
|
+
require 'arelastic/filters/prefix'
|
11
|
+
require 'arelastic/filters/range'
|
12
|
+
require 'arelastic/filters/term'
|
13
|
+
require 'arelastic/filters/terms'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Nodes
|
3
|
+
class HashGroup < Arelastic::Nodes::Node
|
4
|
+
attr_accessor :nodes
|
5
|
+
def initialize nodes
|
6
|
+
@nodes = nodes
|
7
|
+
end
|
8
|
+
|
9
|
+
def as_elastic
|
10
|
+
result = {}
|
11
|
+
nodes.each do |node|
|
12
|
+
result.merge! convert_to_elastic(node)
|
13
|
+
end
|
14
|
+
result
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Nodes
|
3
|
+
class Node
|
4
|
+
extend Arelastic::Arities::Binary
|
5
|
+
extend Arelastic::Arities::Polyadic
|
6
|
+
extend Arelastic::Arities::Unary
|
7
|
+
|
8
|
+
def convert_to_elastic(expr)
|
9
|
+
expr.respond_to?(:as_elastic) ? expr.as_elastic : expr
|
10
|
+
end
|
11
|
+
|
12
|
+
def ==(other)
|
13
|
+
as_elastic == other.as_elastic
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Queries
|
3
|
+
class Filtered < Arelastic::Queries::Query
|
4
|
+
attr_accessor :query, :filter
|
5
|
+
def initialize(query, filter)
|
6
|
+
@query = query
|
7
|
+
@filter = filter
|
8
|
+
end
|
9
|
+
|
10
|
+
def as_elastic
|
11
|
+
{ "filtered" => Arelastic::Nodes::HashGroup.new([query, filter]).as_elastic }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Queries
|
3
|
+
class QueryString < Arelastic::Queries::Query
|
4
|
+
attr_accessor :query_string
|
5
|
+
attr_accessor :options
|
6
|
+
|
7
|
+
def initialize(query_string, options = {})
|
8
|
+
@query_string = query_string
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def as_elastic
|
13
|
+
{"query_string" => {"query" => query_string}}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'arelastic/queries/query'
|
2
|
+
|
3
|
+
require 'arelastic/queries/constant_score'
|
4
|
+
require 'arelastic/queries/field'
|
5
|
+
require 'arelastic/queries/filtered'
|
6
|
+
require 'arelastic/queries/match_all'
|
7
|
+
require 'arelastic/queries/prefix'
|
8
|
+
require 'arelastic/queries/query_string'
|
9
|
+
require 'arelastic/queries/terms'
|
10
|
+
require 'arelastic/queries/term'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Searches
|
3
|
+
class Facets < Arelastic::Searches::Search
|
4
|
+
attr_accessor :grouping
|
5
|
+
def initialize facets
|
6
|
+
@grouping = Arelastic::Nodes::HashGroup.new facets
|
7
|
+
end
|
8
|
+
|
9
|
+
def as_elastic
|
10
|
+
{ "facets" => convert_to_elastic(grouping) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/arelastic.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Arities::BinaryTest < MiniTest::Spec
|
4
|
+
def test_binary
|
5
|
+
node = Class.new(Arelastic::Nodes::Node) do
|
6
|
+
binary 'suffix'
|
7
|
+
end
|
8
|
+
|
9
|
+
expected = {'suffix' => {'phone' => '666'}}
|
10
|
+
assert_equal expected, node.new('phone', '666').as_elastic
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Arities::PolyadicTest < MiniTest::Spec
|
4
|
+
def test_polyadic
|
5
|
+
expr = Struct.new(:as_elastic)
|
6
|
+
node = Class.new(Arelastic::Nodes::Node) do
|
7
|
+
polyadic 'xor'
|
8
|
+
end
|
9
|
+
|
10
|
+
expected = {'xor' => [{'a' => 'b'}, {'x' => 'y'}]}
|
11
|
+
assert_equal expected, node.new([expr.new('a' => 'b'), expr.new('x' => 'y')]).as_elastic
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Arities::UnaryTest < MiniTest::Spec
|
4
|
+
def test_unary
|
5
|
+
node = Class.new(Arelastic::Nodes::Node) do
|
6
|
+
unary 'unicorn'
|
7
|
+
end
|
8
|
+
|
9
|
+
expected = {'unicorn' => 'serenity'}
|
10
|
+
assert_equal expected, node.new('serenity').as_elastic
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Builders::FilterTest < MiniTest::Spec
|
4
|
+
def test_ids
|
5
|
+
expected = {"ids" => {"values"=>["5", "6"]}}
|
6
|
+
assert_equal expected, Arelastic::Builders::Filter.ids('5', '6').as_elastic
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_eq
|
10
|
+
expected = {"term"=>{"color"=>"blue"}}
|
11
|
+
assert_equal expected, builder.eq('blue').as_elastic
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_not_eq
|
15
|
+
expected = {"not" => {"term" => {"color"=>"blue"}}}
|
16
|
+
assert_equal expected, builder.not_eq('blue').as_elastic
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_in
|
20
|
+
expected = {"terms" => {"color"=>["blue"]}}
|
21
|
+
assert_equal expected, builder.in(['blue']).as_elastic
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_in_with_range
|
25
|
+
expected = {"range" => {"color" => {"gte"=>1, "lte"=>3}}}
|
26
|
+
assert_equal expected, builder.in(1..3).as_elastic
|
27
|
+
|
28
|
+
expected = {"range" => {"color" => {"gte"=>1, "lt"=>3}}}
|
29
|
+
assert_equal expected, builder.in(1...3).as_elastic
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_not_in
|
33
|
+
expected = {"not" => {"terms" => {"color"=>["blue"]}}}
|
34
|
+
assert_equal expected, builder.not_in(['blue']).as_elastic
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_prefix
|
38
|
+
expected = {"prefix" => {"color" => "blu"}}
|
39
|
+
assert_equal expected, builder.prefix('blu').as_elastic
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_exists
|
43
|
+
expected = {"exists" => {"field"=>"color"}}
|
44
|
+
assert_equal expected, builder.exists.as_elastic
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_range
|
48
|
+
expected = {"range" => {"color" => {"lt" => 5}}}
|
49
|
+
assert_equal expected, builder.lt(5).as_elastic
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def builder
|
54
|
+
@builder ||= Arelastic::Builders::Filter['color']
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Builders::QueryTest < MiniTest::Spec
|
4
|
+
def test_constant_score
|
5
|
+
query = Arelastic::Builders::Query.constant_score({"foo" => "bar"})
|
6
|
+
expected = {"query" => {"constant_score" => {"foo" => "bar"}}}
|
7
|
+
|
8
|
+
assert_equal expected, query.as_elastic
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_filtered
|
12
|
+
query = Arelastic::Builders::Query.filtered({"query" => "foo"}, {"filter" => "bar"})
|
13
|
+
expected = {"query" => {"filtered" => {"query" => "foo", "filter" => "bar"}}}
|
14
|
+
|
15
|
+
assert_equal expected, query.as_elastic
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_match_all
|
19
|
+
query = Arelastic::Builders::Query.match_all
|
20
|
+
expected = {"query" => {"match_all" => {}}}
|
21
|
+
|
22
|
+
assert_equal expected, query.as_elastic
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_field
|
26
|
+
query = Arelastic::Builders::Query['user'].field 'kimchy'
|
27
|
+
expected = { "field" => { "user" => "kimchy" } }
|
28
|
+
|
29
|
+
assert_equal expected, query.as_elastic
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_term
|
33
|
+
query = Arelastic::Builders::Query['user'].term 'kimchy'
|
34
|
+
expected = {"term" => { "user" => "kimchy" }}
|
35
|
+
|
36
|
+
assert_equal expected, query.as_elastic
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_term
|
40
|
+
query = Arelastic::Builders::Query['tags'].terms ['blue', 'pill']
|
41
|
+
expected = {"terms" => { "tags" => ["blue", "pill"] }}
|
42
|
+
|
43
|
+
assert_equal expected, query.as_elastic
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Facets::TermsTest < MiniTest::Spec
|
4
|
+
def test_as_elastic
|
5
|
+
facet = Arelastic::Facets::Histogram.new('histo', "field" => "field_name", "interval" => 100)
|
6
|
+
expected = {
|
7
|
+
"histo" => {
|
8
|
+
"histogram" => {
|
9
|
+
"field" => "field_name",
|
10
|
+
"interval" => 100
|
11
|
+
}
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
assert_equal expected, facet.as_elastic
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Facets::TermsTest < MiniTest::Spec
|
4
|
+
def test_as_elastic
|
5
|
+
facet = Arelastic::Facets::Terms.new('foo', 'tags', "size" => 10)
|
6
|
+
expected = {
|
7
|
+
"foo" => {
|
8
|
+
"terms" => {
|
9
|
+
"field" => "tags",
|
10
|
+
"size" => 10,
|
11
|
+
}
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
assert_equal expected, facet.as_elastic
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::FilterTest < MiniTest::Spec
|
4
|
+
def test_or
|
5
|
+
filter = Arelastic::Filters::Filter.new
|
6
|
+
|
7
|
+
and_filter = filter.and(filter)
|
8
|
+
|
9
|
+
assert and_filter.is_a?(Arelastic::Filters::And)
|
10
|
+
assert_equal [filter, filter], and_filter.children
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_and
|
14
|
+
filter = Arelastic::Filters::Filter.new
|
15
|
+
|
16
|
+
and_filter = filter.or(filter)
|
17
|
+
|
18
|
+
assert and_filter.is_a?(Arelastic::Filters::Or)
|
19
|
+
assert_equal [filter, filter], and_filter.children
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_negate
|
23
|
+
filter = Arelastic::Filters::Term.new 'foo', 'bar'
|
24
|
+
|
25
|
+
negated_filter = filter.negate
|
26
|
+
|
27
|
+
assert negated_filter.is_a?(Arelastic::Filters::Not)
|
28
|
+
assert_equal filter, negated_filter.expr
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Filters::MissingTest < MiniTest::Spec
|
4
|
+
def test_as_elastic
|
5
|
+
expected = {"missing" => { "field" => "color" }}
|
6
|
+
|
7
|
+
assert_equal expected, Arelastic::Filters::Missing.new('color').as_elastic
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_with_options
|
11
|
+
expected = {"missing" => { "field" => "color", "null_value" => true }}
|
12
|
+
|
13
|
+
assert_equal expected, Arelastic::Filters::Missing.new('color', 'null_value' => true).as_elastic
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Nodes::NodeTest < MiniTest::Spec
|
4
|
+
def test_equality
|
5
|
+
node = Class.new(Arelastic::Nodes::Node) do
|
6
|
+
def initialize(value)
|
7
|
+
@value = value
|
8
|
+
end
|
9
|
+
|
10
|
+
def as_elastic
|
11
|
+
{"value" => @value}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_equal node.new('foo'), node.new('foo')
|
16
|
+
refute_equal node.new('foo'), node.new('bar')
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Queries::FilteredTest < MiniTest::Spec
|
4
|
+
def test_as_elastic
|
5
|
+
filtered = Arelastic::Queries::Filtered.new({"query" => "bar"}, {"filter" => "baz"})
|
6
|
+
expected = {"filtered" => {"query" => "bar", "filter" => "baz"}}
|
7
|
+
|
8
|
+
assert_equal expected, filtered.as_elastic
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Queries::QueryStringTest < MiniTest::Spec
|
4
|
+
def test_as_elastic
|
5
|
+
query_string = Arelastic::Queries::QueryString.new('foo')
|
6
|
+
expected = {"query_string" => {"query" => "foo"}}
|
7
|
+
|
8
|
+
assert_equal expected, query_string.as_elastic
|
9
|
+
end
|
10
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arelastic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matthew Higgins
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-23 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Build Elastic Search queries with objects
|
15
|
+
email: developer@matthewhiggins.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README.rdoc
|
20
|
+
files:
|
21
|
+
- lib/arelastic/arities/binary.rb
|
22
|
+
- lib/arelastic/arities/polyadic.rb
|
23
|
+
- lib/arelastic/arities/unary.rb
|
24
|
+
- lib/arelastic/arities.rb
|
25
|
+
- lib/arelastic/builders/facet.rb
|
26
|
+
- lib/arelastic/builders/filter.rb
|
27
|
+
- lib/arelastic/builders/query.rb
|
28
|
+
- lib/arelastic/builders/search.rb
|
29
|
+
- lib/arelastic/builders/sort.rb
|
30
|
+
- lib/arelastic/builders.rb
|
31
|
+
- lib/arelastic/facets/facet.rb
|
32
|
+
- lib/arelastic/facets/histogram.rb
|
33
|
+
- lib/arelastic/facets/range.rb
|
34
|
+
- lib/arelastic/facets/terms.rb
|
35
|
+
- lib/arelastic/facets.rb
|
36
|
+
- lib/arelastic/filters/and.rb
|
37
|
+
- lib/arelastic/filters/exists.rb
|
38
|
+
- lib/arelastic/filters/filter.rb
|
39
|
+
- lib/arelastic/filters/ids.rb
|
40
|
+
- lib/arelastic/filters/limit.rb
|
41
|
+
- lib/arelastic/filters/missing.rb
|
42
|
+
- lib/arelastic/filters/not.rb
|
43
|
+
- lib/arelastic/filters/or.rb
|
44
|
+
- lib/arelastic/filters/prefix.rb
|
45
|
+
- lib/arelastic/filters/range.rb
|
46
|
+
- lib/arelastic/filters/term.rb
|
47
|
+
- lib/arelastic/filters/terms.rb
|
48
|
+
- lib/arelastic/filters.rb
|
49
|
+
- lib/arelastic/nodes/hash_group.rb
|
50
|
+
- lib/arelastic/nodes/node.rb
|
51
|
+
- lib/arelastic/nodes.rb
|
52
|
+
- lib/arelastic/queries/constant_score.rb
|
53
|
+
- lib/arelastic/queries/field.rb
|
54
|
+
- lib/arelastic/queries/filtered.rb
|
55
|
+
- lib/arelastic/queries/match_all.rb
|
56
|
+
- lib/arelastic/queries/prefix.rb
|
57
|
+
- lib/arelastic/queries/query.rb
|
58
|
+
- lib/arelastic/queries/query_string.rb
|
59
|
+
- lib/arelastic/queries/term.rb
|
60
|
+
- lib/arelastic/queries/terms.rb
|
61
|
+
- lib/arelastic/queries.rb
|
62
|
+
- lib/arelastic/searches/facets.rb
|
63
|
+
- lib/arelastic/searches/filter.rb
|
64
|
+
- lib/arelastic/searches/from.rb
|
65
|
+
- lib/arelastic/searches/query.rb
|
66
|
+
- lib/arelastic/searches/search.rb
|
67
|
+
- lib/arelastic/searches/size.rb
|
68
|
+
- lib/arelastic/searches/sort.rb
|
69
|
+
- lib/arelastic/searches.rb
|
70
|
+
- lib/arelastic.rb
|
71
|
+
- test/arelastic/arities/binary_test.rb
|
72
|
+
- test/arelastic/arities/polyadic_test.rb
|
73
|
+
- test/arelastic/arities/unary_test.rb
|
74
|
+
- test/arelastic/builders/filter_test.rb
|
75
|
+
- test/arelastic/builders/query_test.rb
|
76
|
+
- test/arelastic/builders/search_test.rb
|
77
|
+
- test/arelastic/builders/sort_test.rb
|
78
|
+
- test/arelastic/facets/histogram_test.rb
|
79
|
+
- test/arelastic/facets/terms_test.rb
|
80
|
+
- test/arelastic/filters/exists_test.rb
|
81
|
+
- test/arelastic/filters/filter_test.rb
|
82
|
+
- test/arelastic/filters/ids_test.rb
|
83
|
+
- test/arelastic/filters/missing_test.rb
|
84
|
+
- test/arelastic/filters/not_test.rb
|
85
|
+
- test/arelastic/nodes/node_test.rb
|
86
|
+
- test/arelastic/queries/filtered_test.rb
|
87
|
+
- test/arelastic/queries/match_all_test.rb
|
88
|
+
- test/arelastic/queries/query_string_test.rb
|
89
|
+
- test/arelastic/queries/query_test.rb
|
90
|
+
- test/helper.rb
|
91
|
+
- README.rdoc
|
92
|
+
homepage: http://github.com/matthuhiggins/arelastic
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 1.9.3
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.8.11
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.24
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Elastic Search query builder
|
117
|
+
test_files: []
|