elasticband 0.1.9 → 0.1.10

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGNmMTIxZjU0NmI4MjA2MGQxMmU3Y2UwZWYyZDlkMmU4MDJlMmFiYg==
4
+ OWFmNDU0YTUwMGZjYmQwOWU1ZTBkMWMyNWJmMzNhYmQ0NjM4NmMxMQ==
5
5
  data.tar.gz: !binary |-
6
- ZGM2YmVjZTc4MmQzNjJhNmE4OTBiMzJkNWE3MjVmNzBjMjI5MTJiZg==
6
+ Yzg4YTQzM2M3ODM5Zjk3Nzg3MWYyY2JmOTFjY2U5MDAzMmI2OGVhOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDc2Yzg4M2VkYzIyZDI5ZDMyOTQ3OTNmNWI2YTYyMTcxOTg1MDZjM2Y4YTBk
10
- OWU3Yzk5MzFlNGVmOWNjMDkzNWIzNDkwMzllNjAwZDRhYzNmYTUwMDE4NWEw
11
- OTNlMjkzYTI4NWM0NWVjYmUyYjM0NGM2YWJkNzgwNmEwOTYxMDE=
9
+ N2NkOGUwZGUzMWIzNjBiMmZkZWRkOGQ1NTBhOGUwYWQ5ZDA3YTFmOTg5OGQ0
10
+ ODFjMjdiZWNiMWFiNGIyZjc1YWE0ZjhkYmNkY2UyZjVmYmRjYjRiYTQ0YWRm
11
+ YjBmODRmMmZjZGVlZTRjM2JhNmIwOTEyYmEyMzE0YjFmZjExNWE=
12
12
  data.tar.gz: !binary |-
13
- MGM5OTc3Y2NkMmY5MWY3OGVhNTZlZTM3OTlhYjlhYjFiNDA0MmEyMmJlNzhh
14
- ZDE1Njg5NzNmZmNjMWIzZTg1ZDMxMzM1NzFlZDFjYTg4OTdlYWQ5ZDgwZDc2
15
- NDFkMTIxMzc0Yzc5ODE3YjcxMDJkMTNiNWIwNTk1YWQzNmMzMzQ=
13
+ YzUzMGVkM2FjY2IzMDIzZTM4M2VjMWQwODYxYmQzYTg2ODkzMWEzMzE1ODhm
14
+ NDc0ZmY1ODBiMWZmNzhiOWMzMjVhMmY4MjZjNTJjYzgyNDNiZjY2MjQwNWRh
15
+ MWMwZjY3NjU1YmJiY2RhYzljM2YyYzAzNTllYTc3ODk5OWYxOWY=
@@ -73,8 +73,8 @@ module Elasticband
73
73
  query = parse_boost(
74
74
  query,
75
75
  options.slice(:boost_by, :boost_where, :boost_function),
76
- options.slice(:score_mode),
77
- options.slice(:boost_mode)
76
+ options[:score_mode],
77
+ options[:boost_mode]
78
78
  )
79
79
  query.to_h
80
80
  end
@@ -1,3 +1,3 @@
1
1
  module Elasticband
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.10'
3
3
  end
data/spec/query_spec.rb CHANGED
@@ -67,6 +67,40 @@ RSpec.describe Elasticband::Query do
67
67
  }
68
68
  )
69
69
  end
70
+
71
+ context 'with `:boost_mode` option' do
72
+ let(:options) { { boost_by: :contents_count, boost_mode: :multiply } }
73
+
74
+ it 'returns a function score query with the boost_mode' do
75
+ is_expected.to eq(
76
+ function_score: {
77
+ query: { match: { _all: 'foo' } },
78
+ boost_mode: :multiply,
79
+ field_value_factor: {
80
+ field: :contents_count,
81
+ modifier: :ln2p
82
+ }
83
+ }
84
+ )
85
+ end
86
+ end
87
+
88
+ context 'with `:score_mode` option' do
89
+ let(:options) { { boost_by: :contents_count, score_mode: :multiply } }
90
+
91
+ it 'returns a function score query with the score_mode' do
92
+ is_expected.to eq(
93
+ function_score: {
94
+ query: { match: { _all: 'foo' } },
95
+ score_mode: :multiply,
96
+ field_value_factor: {
97
+ field: :contents_count,
98
+ modifier: :ln2p
99
+ }
100
+ }
101
+ )
102
+ end
103
+ end
70
104
  end
71
105
 
72
106
  context 'with `:boost_function` option' do
@@ -83,6 +117,38 @@ RSpec.describe Elasticband::Query do
83
117
  }
84
118
  )
85
119
  end
120
+
121
+ context 'with `:boost_mode` option' do
122
+ let(:options) { { boost_function: "_score * doc['users_count'].value", boost_mode: :multiply } }
123
+
124
+ it 'returns a function score query with the boost_mode' do
125
+ is_expected.to eq(
126
+ function_score: {
127
+ query: { match: { _all: 'foo' } },
128
+ boost_mode: :multiply,
129
+ script_score: {
130
+ script: "_score * doc['users_count'].value"
131
+ }
132
+ }
133
+ )
134
+ end
135
+ end
136
+
137
+ context 'with `:score_mode` option' do
138
+ let(:options) { { boost_function: "_score * doc['users_count'].value", score_mode: :multiply } }
139
+
140
+ it 'returns a function score query with the score_mode' do
141
+ is_expected.to eq(
142
+ function_score: {
143
+ query: { match: { _all: 'foo' } },
144
+ score_mode: :multiply,
145
+ script_score: {
146
+ script: "_score * doc['users_count'].value"
147
+ }
148
+ }
149
+ )
150
+ end
151
+ end
86
152
  end
87
153
 
88
154
  context 'with params' do
@@ -127,6 +193,44 @@ RSpec.describe Elasticband::Query do
127
193
  }
128
194
  )
129
195
  end
196
+
197
+ context 'with `:boost_mode` option' do
198
+ let(:options) { { boost_where: { status: :published }, boost_mode: :multiply } }
199
+
200
+ it 'returns a function score query with the boost_mode' do
201
+ is_expected.to eq(
202
+ function_score: {
203
+ query: { match: { _all: 'foo' } },
204
+ boost_mode: :multiply,
205
+ functions: [
206
+ {
207
+ filter: { name: 'filter' },
208
+ boost_factor: 1000
209
+ }
210
+ ]
211
+ }
212
+ )
213
+ end
214
+ end
215
+
216
+ context 'with `:score_mode` option' do
217
+ let(:options) { { boost_where: { status: :published }, score_mode: :multiply } }
218
+
219
+ it 'returns a function score query with the score_mode' do
220
+ is_expected.to eq(
221
+ function_score: {
222
+ query: { match: { _all: 'foo' } },
223
+ score_mode: :multiply,
224
+ functions: [
225
+ {
226
+ filter: { name: 'filter' },
227
+ boost_factor: 1000
228
+ }
229
+ ]
230
+ }
231
+ )
232
+ end
233
+ end
130
234
  end
131
235
  end
132
236
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticband
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glauber Campinho