Commit 931fe97212a5260845b2396f32c1b56ccb966055
Committed by
Andrew Kane
1 parent
0defdd40
Exists in
master
and in
19 other branches
Enhance boost by distance with factor (#1028)
Showing
2 changed files
with
12 additions
and
0 deletions
Show diff stats
lib/searchkick/query.rb
@@ -551,6 +551,7 @@ module Searchkick | @@ -551,6 +551,7 @@ module Searchkick | ||
551 | function_params = attributes.select { |k, _| [:origin, :scale, :offset, :decay].include?(k) } | 551 | function_params = attributes.select { |k, _| [:origin, :scale, :offset, :decay].include?(k) } |
552 | function_params[:origin] = location_value(function_params[:origin]) | 552 | function_params[:origin] = location_value(function_params[:origin]) |
553 | custom_filters << { | 553 | custom_filters << { |
554 | + :weight => attributes[:factor] || 1, | ||
554 | attributes[:function] => { | 555 | attributes[:function] => { |
555 | field => function_params | 556 | field => function_params |
556 | } | 557 | } |
test/boost_test.rb
@@ -191,6 +191,17 @@ class BoostTest < Minitest::Test | @@ -191,6 +191,17 @@ class BoostTest < Minitest::Test | ||
191 | assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {location: {origin: {lat: 37, lon: -122}, scale: "1000mi"}} | 191 | assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {location: {origin: {lat: 37, lon: -122}, scale: "1000mi"}} |
192 | end | 192 | end |
193 | 193 | ||
194 | + def test_boost_by_distance_v2_factor | ||
195 | + store [ | ||
196 | + {name: "San Francisco", latitude: 37.7833, longitude: -122.4167, found_rate: 0.1}, | ||
197 | + {name: "San Antonio", latitude: 29.4167, longitude: -98.5000, found_rate: 0.99}, | ||
198 | + {name: "San Marino", latitude: 43.9333, longitude: 12.4667, found_rate: 0.2} | ||
199 | + ] | ||
200 | + | ||
201 | + assert_order "san", ["San Antonio","San Francisco", "San Marino"], boost_by: {found_rate: {factor: 100}},boost_by_distance: {location: {origin: [37, -122], scale: "1000mi"}} | ||
202 | + assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by: {found_rate: {factor: 100}} , boost_by_distance: {location: {origin: [37, -122], scale: "1000mi", factor: 100}} | ||
203 | + end | ||
204 | + | ||
194 | def test_boost_by_indices | 205 | def test_boost_by_indices |
195 | skip if cequel? | 206 | skip if cequel? |
196 | 207 |