Commit fdc799d6f22c7549f38715a42265db701d389ff9

Authored by Andrew
1 parent dc19c470

Raise errors when invalid arguments [skip ci]

Showing 1 changed file with 22 additions and 19 deletions   Show diff stats
lib/searchkick/query.rb
... ... @@ -587,7 +587,7 @@ module Searchkick
587 587 if boost_by.is_a?(Array)
588 588 boost_by = Hash[boost_by.map { |f| [f, {factor: 1}] }]
589 589 elsif boost_by.is_a?(Hash)
590   - multiply_by, boost_by = boost_by.partition { |_, v| v[:boost_mode] == "multiply" }.map { |i| Hash[i] }
  590 + multiply_by, boost_by = boost_by.partition { |_, v| v.delete(:boost_mode) == "multiply" }.map { |i| Hash[i] }
591 591 end
592 592 boost_by[options[:boost]] = {factor: 1} if options[:boost]
593 593  
... ... @@ -906,28 +906,31 @@ module Searchkick
906 906 }
907 907 end
908 908  
909   - def boost_filters(boost_by, modifier: nil)
910   - boost_by.map do |field, value|
911   - raise ArgumentError, "Use modifier: \"ln2p\" instead" if value.key?(:log)
912   - script_score = {
913   - field_value_factor: {
914   - field: field,
915   - factor: (value[:factor] || 1).to_f,
916   - modifier: value[:modifier] || modifier
917   - }
  909 + def boost_filter(field, factor: 1, modifier: nil, missing: nil)
  910 + script_score = {
  911 + field_value_factor: {
  912 + field: field,
  913 + factor: factor.to_f,
  914 + modifier: modifier
918 915 }
  916 + }
919 917  
920   - if value[:missing]
921   - script_score[:field_value_factor][:missing] = value[:missing].to_f
922   - else
923   - script_score[:filter] = {
924   - exists: {
925   - field: field
926   - }
  918 + if missing
  919 + script_score[:field_value_factor][:missing] = missing.to_f
  920 + else
  921 + script_score[:filter] = {
  922 + exists: {
  923 + field: field
927 924 }
928   - end
  925 + }
  926 + end
929 927  
930   - script_score
  928 + script_score
  929 + end
  930 +
  931 + def boost_filters(boost_by, modifier: nil)
  932 + boost_by.map do |field, value|
  933 + boost_filter(field, modifier: modifier, **value)
931 934 end
932 935 end
933 936  
... ...