Commit 0f5dd5af62f706d42e919584a94edaaf93096de9

Authored by Andrew
1 parent 587c225e

Moved conversions to own function

Showing 1 changed file with 28 additions and 25 deletions   Show diff stats
lib/searchkick/query.rb
... ... @@ -219,8 +219,6 @@ module Searchkick
219 219 # model and eager loading
220 220 load = options[:load].nil? ? true : options[:load]
221 221  
222   - conversions_fields = Array(options[:conversions] || searchkick_options[:conversions]).map(&:to_s)
223   -
224 222 all = term == "*"
225 223  
226 224 @json = options[:body]
... ... @@ -397,29 +395,7 @@ module Searchkick
397 395 }
398 396 }
399 397  
400   - if conversions_fields.present? && options[:conversions] != false
401   - conversions_fields.each do |conversions_field|
402   - should << {
403   - nested: {
404   - path: conversions_field,
405   - score_mode: "sum",
406   - query: {
407   - function_score: {
408   - boost_mode: "replace",
409   - query: {
410   - match: {
411   - "#{conversions_field}.query" => options[:conversions_term] || term
412   - }
413   - },
414   - field_value_factor: {
415   - field: "#{conversions_field}.count"
416   - }
417   - }
418   - }
419   - }
420   - }
421   - end
422   - end
  398 + set_conversions(should)
423 399  
424 400 query = payload
425 401 end
... ... @@ -561,6 +537,33 @@ module Searchkick
561 537 [boost_fields, fields]
562 538 end
563 539  
  540 + def set_conversions(should)
  541 + conversions_fields = Array(options[:conversions] || searchkick_options[:conversions]).map(&:to_s)
  542 + if conversions_fields.present? && options[:conversions] != false
  543 + conversions_fields.each do |conversions_field|
  544 + should << {
  545 + nested: {
  546 + path: conversions_field,
  547 + score_mode: "sum",
  548 + query: {
  549 + function_score: {
  550 + boost_mode: "replace",
  551 + query: {
  552 + match: {
  553 + "#{conversions_field}.query" => options[:conversions_term] || term
  554 + }
  555 + },
  556 + field_value_factor: {
  557 + field: "#{conversions_field}.count"
  558 + }
  559 + }
  560 + }
  561 + }
  562 + }
  563 + end
  564 + end
  565 + end
  566 +
564 567 def set_boost_by_distance(custom_filters)
565 568 boost_by_distance = options[:boost_by_distance] || {}
566 569  
... ...