Commit 5b1b1e1898a055c48bdeb7d46b2b84b6c8d979f5

Authored by Andrew
1 parent 8307c511

Cleaner code (sort of) [skip ci]

Showing 1 changed file with 11 additions and 7 deletions   Show diff stats
lib/searchkick/query.rb
... ... @@ -363,7 +363,9 @@ module Searchkick
363 363  
364 364 queries.concat(queries_to_add)
365 365  
366   - set_exclude(must_not, exclude_field, exclude_analyzer) if options[:exclude]
  366 + if options[:exclude]
  367 + must_not.concat(set_exclude(exclude_field, exclude_analyzer))
  368 + end
367 369 end
368 370  
369 371 payload = {
... ... @@ -372,7 +374,7 @@ module Searchkick
372 374 }
373 375 }
374 376  
375   - set_conversions(should)
  377 + should.concat(set_conversions)
376 378  
377 379 query = payload
378 380 end
... ... @@ -514,11 +516,11 @@ module Searchkick
514 516 [boost_fields, fields]
515 517 end
516 518  
517   - def set_conversions(should)
  519 + def set_conversions
518 520 conversions_fields = Array(options[:conversions] || searchkick_options[:conversions]).map(&:to_s)
519 521 if conversions_fields.present? && options[:conversions] != false
520   - conversions_fields.each do |conversions_field|
521   - should << {
  522 + conversions_fields.map do |conversions_field|
  523 + {
522 524 nested: {
523 525 path: conversions_field,
524 526 score_mode: "sum",
... ... @@ -538,12 +540,14 @@ module Searchkick
538 540 }
539 541 }
540 542 end
  543 + else
  544 + []
541 545 end
542 546 end
543 547  
544   - def set_exclude(must_not, field, analyzer)
  548 + def set_exclude(field, analyzer)
545 549 Array(options[:exclude]).map do |phrase|
546   - must_not << {
  550 + {
547 551 multi_match: {
548 552 fields: [field],
549 553 query: phrase,
... ...