daedal 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +16 -15
- data/README.md +1 -0
- data/lib/daedal.rb +2 -0
- data/lib/daedal/attributes/score_function_array.rb +24 -0
- data/lib/daedal/queries/function_score_query.rb +37 -0
- data/lib/daedal/version.rb +1 -1
- data/spec/unit/daedal/queries/function_score_query_spec.rb +55 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67944926b6a5ef6c6eb5165191a03f089e784c89
|
4
|
+
data.tar.gz: 0082ced2272905533bf4eae8912abb2bdb178ab6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2a28d5bc4314a4827127eee9c300e14fefc2417c2fd25c7bd660d19f41a40bab560d051365c2449da4ee163a3c039e186ae5790b379022b13ad850a4128173e
|
7
|
+
data.tar.gz: 80b821a4d5050ec57b8806548e1e2768a93b0b4af8df6b9299f11ba228950080aec796c201bb660d93585523fdccea9130e66c2954a5353d615fd095a6514f00
|
data/Gemfile.lock
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
daedal (0.0.
|
4
|
+
daedal (0.0.16)
|
5
5
|
virtus (>= 1.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
axiom-types (0.
|
11
|
-
descendants_tracker (~> 0.0.
|
12
|
-
ice_nine (~> 0.
|
13
|
-
|
10
|
+
axiom-types (0.1.1)
|
11
|
+
descendants_tracker (~> 0.0.4)
|
12
|
+
ice_nine (~> 0.11.0)
|
13
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
14
14
|
celluloid (0.15.2)
|
15
15
|
timers (~> 1.1.0)
|
16
16
|
coderay (1.1.0)
|
17
|
-
coercible (0.
|
18
|
-
backports (~> 3.0, >= 3.1.0)
|
17
|
+
coercible (1.0.0)
|
19
18
|
descendants_tracker (~> 0.0.1)
|
20
19
|
coveralls (0.7.0)
|
21
20
|
multi_json (~> 1.3)
|
@@ -23,9 +22,10 @@ GEM
|
|
23
22
|
simplecov (>= 0.7)
|
24
23
|
term-ansicolor
|
25
24
|
thor
|
26
|
-
descendants_tracker (0.0.
|
25
|
+
descendants_tracker (0.0.4)
|
26
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
27
27
|
diff-lcs (1.2.5)
|
28
|
-
equalizer (0.0.
|
28
|
+
equalizer (0.0.11)
|
29
29
|
ffi (1.9.3)
|
30
30
|
formatador (0.2.4)
|
31
31
|
fuubar (1.2.1)
|
@@ -41,7 +41,7 @@ GEM
|
|
41
41
|
guard-rspec (4.2.0)
|
42
42
|
guard (>= 2.1.1)
|
43
43
|
rspec (>= 2.14, < 4.0)
|
44
|
-
ice_nine (0.
|
44
|
+
ice_nine (0.11.1)
|
45
45
|
listen (2.4.0)
|
46
46
|
celluloid (>= 0.15.2)
|
47
47
|
rb-fsevent (>= 0.9.3)
|
@@ -77,13 +77,14 @@ GEM
|
|
77
77
|
term-ansicolor (1.2.2)
|
78
78
|
tins (~> 0.8)
|
79
79
|
thor (0.18.1)
|
80
|
+
thread_safe (0.3.5)
|
80
81
|
timers (1.1.0)
|
81
82
|
tins (0.13.1)
|
82
|
-
virtus (1.0.
|
83
|
-
axiom-types (~> 0.
|
84
|
-
coercible (~> 0
|
85
|
-
descendants_tracker (~> 0.0.
|
86
|
-
equalizer (~> 0.0.
|
83
|
+
virtus (1.0.2)
|
84
|
+
axiom-types (~> 0.1)
|
85
|
+
coercible (~> 1.0)
|
86
|
+
descendants_tracker (~> 0.0.3)
|
87
|
+
equalizer (~> 0.0.9)
|
87
88
|
|
88
89
|
PLATFORMS
|
89
90
|
ruby
|
data/README.md
CHANGED
@@ -92,6 +92,7 @@ bool_query.to_json # => "{\"bool\":{\"should\":[{\"match\":{\"lines\":{\"query\"
|
|
92
92
|
Currently, the following queries have been implemented:
|
93
93
|
* [bool query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)
|
94
94
|
* [constant score query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html)
|
95
|
+
* [function score query](http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)
|
95
96
|
* [dis max query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html)
|
96
97
|
* [filtered query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html)
|
97
98
|
* [fuzzy query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html)
|
data/lib/daedal.rb
CHANGED
@@ -19,6 +19,7 @@ require 'daedal/attributes/filter'
|
|
19
19
|
require 'daedal/attributes/field'
|
20
20
|
require 'daedal/attributes/query_value'
|
21
21
|
require 'daedal/attributes/boost'
|
22
|
+
require 'daedal/attributes/score_function_array'
|
22
23
|
|
23
24
|
# filters
|
24
25
|
require 'daedal/filters/exists_filter'
|
@@ -47,5 +48,6 @@ require 'daedal/queries/query_string_query'
|
|
47
48
|
require 'daedal/queries/term_query'
|
48
49
|
require 'daedal/queries/terms_query'
|
49
50
|
require 'daedal/queries/range_query'
|
51
|
+
require 'daedal/queries/function_score_query'
|
50
52
|
|
51
53
|
# facets
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Daedal
|
2
|
+
module Attributes
|
3
|
+
"""Custom coercer for the type attribute"""
|
4
|
+
class ScoreFunctionArray < Array
|
5
|
+
def <<(function)
|
6
|
+
raise Virtus::CoercionError.new(value, 'Daedal::Attributes::ScoreFunction') unless valid_score_function?(function)
|
7
|
+
|
8
|
+
super function
|
9
|
+
end
|
10
|
+
|
11
|
+
def unshift(function)
|
12
|
+
raise Virtus::CoercionError.new(f, 'Daedal::Attributes::ScoreFunctions') unless valid_score_function?(function)
|
13
|
+
|
14
|
+
super function
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# Values should be an array of hashes with filter & weight
|
19
|
+
def valid_score_function?(score_function)
|
20
|
+
score_function[:filter].respond_to?(:hash) && score_function[:weight].respond_to?(:hash)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Daedal
|
2
|
+
module Queries
|
3
|
+
"""Class for the function score query"""
|
4
|
+
class FunctionScoreQuery < Query
|
5
|
+
|
6
|
+
# required attributes
|
7
|
+
attribute :query, Daedal::Attributes::Query
|
8
|
+
attribute :score_functions, Daedal::Attributes::ScoreFunctionArray
|
9
|
+
|
10
|
+
# non required attributes
|
11
|
+
attribute :boost, Daedal::Attributes::Boost, required: false
|
12
|
+
attribute :score_mode, Daedal::Attributes::LowerCaseString, required: false
|
13
|
+
attribute :filter, Daedal::Attributes::Filter, required: false
|
14
|
+
|
15
|
+
def to_hash
|
16
|
+
{
|
17
|
+
function_score: {
|
18
|
+
query: build_query,
|
19
|
+
functions: score_functions.map { |f| { filter: f[:filter].to_hash, weight: f[:weight] } },
|
20
|
+
boost: boost || 1,
|
21
|
+
score_mode: score_mode || "multiply"
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def build_query
|
29
|
+
if filter
|
30
|
+
{ filtered: { query: query.to_hash, filter: filter.to_hash } }
|
31
|
+
else
|
32
|
+
query.to_hash
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/daedal/version.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Daedal::Queries::FunctionScoreQuery do
|
4
|
+
|
5
|
+
let(:score_functions) do
|
6
|
+
[
|
7
|
+
filter: Daedal::Filters::TermFilter.new(field: :foo, term: :bar),
|
8
|
+
weight: 100
|
9
|
+
]
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:query) do
|
13
|
+
Daedal::Queries::MatchAllQuery.new
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:filter) do
|
17
|
+
Daedal::Filters::TermFilter.new(field: :foo, term: :bar)
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'without a query specified' do
|
21
|
+
it 'will raise an error' do
|
22
|
+
expect{ described_class.new(score_functions: score_functions) }.to raise_error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'without a boost specified' do
|
27
|
+
it 'will raise an error' do
|
28
|
+
expect{ described_class.new(query: query, score_functions: score_functions) }.to raise_error(Virtus::CoercionError)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with valid arguments' do
|
33
|
+
it 'converts to a valid query with filter' do
|
34
|
+
valid_query = described_class.new(query: query, score_functions: score_functions,
|
35
|
+
filter: filter, boost: 42, score_mode: 'sum')
|
36
|
+
expect(valid_query.to_hash[:function_score][:query][:filtered][:query]).to eq(query.to_hash)
|
37
|
+
expect(valid_query.to_hash[:function_score][:query][:filtered][:filter]).to eq(filter.to_hash)
|
38
|
+
expect(valid_query.to_hash[:function_score][:functions]).to eq(score_functions.map do |f|
|
39
|
+
{ :filter => f[:filter].to_hash, :weight => f[:weight] }
|
40
|
+
end)
|
41
|
+
expect(valid_query.to_hash[:function_score][:boost]).to eq(42)
|
42
|
+
expect(valid_query.to_hash[:function_score][:score_mode]).to eq('sum')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'converts to a valid query without filter' do
|
46
|
+
valid_query = described_class.new(query: query, score_functions: score_functions, boost: 42, score_mode: 'sum')
|
47
|
+
expect(valid_query.to_hash[:function_score][:query]).to eq(query.to_hash)
|
48
|
+
expect(valid_query.to_hash[:function_score][:functions]).to eq(score_functions.map do |f|
|
49
|
+
{ :filter => f[:filter].to_hash, :weight => f[:weight] }
|
50
|
+
end)
|
51
|
+
expect(valid_query.to_hash[:function_score][:boost]).to eq(42)
|
52
|
+
expect(valid_query.to_hash[:function_score][:score_mode]).to eq('sum')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daedal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Schuch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- lib/daedal/attributes/query.rb
|
53
53
|
- lib/daedal/attributes/query_array.rb
|
54
54
|
- lib/daedal/attributes/query_value.rb
|
55
|
+
- lib/daedal/attributes/score_function_array.rb
|
55
56
|
- lib/daedal/attributes/score_mode.rb
|
56
57
|
- lib/daedal/facets/facet.rb
|
57
58
|
- lib/daedal/filters/and_filter.rb
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- lib/daedal/queries/constant_score_query.rb
|
70
71
|
- lib/daedal/queries/dis_max_query.rb
|
71
72
|
- lib/daedal/queries/filtered_query.rb
|
73
|
+
- lib/daedal/queries/function_score_query.rb
|
72
74
|
- lib/daedal/queries/fuzzy_query.rb
|
73
75
|
- lib/daedal/queries/match_all_query.rb
|
74
76
|
- lib/daedal/queries/match_query.rb
|
@@ -96,6 +98,7 @@ files:
|
|
96
98
|
- spec/unit/daedal/queries/constant_score_query_spec.rb
|
97
99
|
- spec/unit/daedal/queries/dis_max_query_spec.rb
|
98
100
|
- spec/unit/daedal/queries/filtered_query_spec.rb
|
101
|
+
- spec/unit/daedal/queries/function_score_query_spec.rb
|
99
102
|
- spec/unit/daedal/queries/fuzzy_query_spec.rb
|
100
103
|
- spec/unit/daedal/queries/match_all_query_spec.rb
|
101
104
|
- spec/unit/daedal/queries/match_query_spec.rb
|