Commit 3344b243a844a95fb4316074ca7cf89d238d21f4

Authored by Andrew Kane
1 parent 45817046

Correct use of && and ||

lib/searchkick/index.rb
... ... @@ -76,7 +76,7 @@ module Searchkick
76 76 end
77 77  
78 78 def reindex_record(record)
79   - if record.destroyed? or !record.should_index?
  79 + if record.destroyed? || !record.should_index?
80 80 begin
81 81 remove(record)
82 82 rescue Elasticsearch::Transport::Transport::Errors::NotFound
... ... @@ -200,7 +200,7 @@ module Searchkick
200 200 def index_options
201 201 options = @options
202 202  
203   - if options[:mappings] and !options[:merge_mappings]
  203 + if options[:mappings] && !options[:merge_mappings]
204 204 settings = options[:settings] || {}
205 205 mappings = options[:mappings]
206 206 else
... ... @@ -492,7 +492,7 @@ module Searchkick
492 492  
493 493 # conversions
494 494 conversions_field = options[:conversions]
495   - if conversions_field and source[conversions_field]
  495 + if conversions_field && source[conversions_field]
496 496 source[conversions_field] = source[conversions_field].map{|k, v| {query: k, count: v} }
497 497 end
498 498  
... ...
lib/searchkick/query.rb
... ... @@ -98,7 +98,7 @@ module Searchkick
98 98 boost: factor
99 99 }
100 100  
101   - if field == "_all" or field.end_with?(".analyzed")
  101 + if field == "_all" || field.end_with?(".analyzed")
102 102 shared_options[:cutoff_frequency] = 0.001 unless operator == "and"
103 103 qs.concat [
104 104 shared_options.merge(boost: 10 * factor, analyzer: "searchkick_search"),
... ... @@ -130,7 +130,7 @@ module Searchkick
130 130 }
131 131 end
132 132  
133   - if conversions_field and options[:conversions] != false
  133 + if conversions_field && options[:conversions] != false
134 134 # wrap payload in a bool query
135 135 script_score =
136 136 if below12
... ... @@ -191,14 +191,14 @@ module Searchkick
191 191 end
192 192  
193 193 boost_where = options[:boost_where] || {}
194   - if options[:user_id] and personalize_field
  194 + if options[:user_id] && personalize_field
195 195 boost_where[personalize_field] = options[:user_id]
196 196 end
197 197 if options[:personalize]
198 198 boost_where = boost_where.merge(options[:personalize])
199 199 end
200 200 boost_where.each do |field, value|
201   - if value.is_a?(Array) and value.first.is_a?(Hash)
  201 + if value.is_a?(Array) && value.first.is_a?(Hash)
202 202 value.each do |value_factor|
203 203 value, factor = value_factor[:value], value_factor[:factor]
204 204 custom_filters << custom_filter(field, value, factor)
... ... @@ -215,7 +215,7 @@ module Searchkick
215 215 boost_by_distance = options[:boost_by_distance]
216 216 if boost_by_distance
217 217 boost_by_distance = {function: :gauss, scale: "5mi"}.merge(boost_by_distance)
218   - if !boost_by_distance[:field] or !boost_by_distance[:origin]
  218 + if !boost_by_distance[:field] || !boost_by_distance[:origin]
219 219 raise ArgumentError, "boost_by_distance requires :field and :origin"
220 220 end
221 221 function_params = boost_by_distance.select{|k,v| [:origin, :scale, :offset, :decay].include?(k) }
... ... @@ -364,7 +364,7 @@ module Searchkick
364 364 payload[:fields] = []
365 365 end
366 366  
367   - if options[:type] or klass != searchkick_klass
  367 + if options[:type] || klass != searchkick_klass
368 368 @type = [options[:type] || klass].flatten.map{|v| searchkick_index.klass_document_type(v) }
369 369 end
370 370 end
... ... @@ -405,10 +405,10 @@ module Searchkick
405 405 status_code = e.message[1..3].to_i
406 406 if status_code == 404
407 407 raise MissingIndexError, "Index missing - run #{searchkick_klass.name}.reindex"
408   - elsif status_code == 500 and (
409   - e.message.include?("IllegalArgumentException[minimumSimilarity >= 1]") or
410   - e.message.include?("No query registered for [multi_match]") or
411   - e.message.include?("[match] query does not support [cutoff_frequency]]") or
  408 + elsif status_code == 500 && (
  409 + e.message.include?("IllegalArgumentException[minimumSimilarity >= 1]") ||
  410 + e.message.include?("No query registered for [multi_match]") ||
  411 + e.message.include?("[match] query does not support [cutoff_frequency]]") ||
412 412 e.message.include?("No query registered for [function_score]]")
413 413 )
414 414  
... ...
lib/searchkick/reindex_job.rb
... ... @@ -10,7 +10,7 @@ module Searchkick
10 10 model = @klass.constantize
11 11 record = model.find(@id) rescue nil # TODO fix lazy coding
12 12 index = model.searchkick_index
13   - if !record or !record.should_index?
  13 + if !record || !record.should_index?
14 14 # hacky
15 15 record ||= model.new
16 16 record.id = @id
... ...
lib/searchkick/reindex_v2_job.rb
... ... @@ -6,7 +6,7 @@ module Searchkick
6 6 model = klass.constantize
7 7 record = model.find(id) rescue nil # TODO fix lazy coding
8 8 index = model.searchkick_index
9   - if !record or !record.should_index?
  9 + if !record || !record.should_index?
10 10 # hacky
11 11 record ||= model.new
12 12 record.id = id
... ...
lib/searchkick/results.rb
... ... @@ -24,7 +24,7 @@ module Searchkick
24 24 hits.group_by{|hit, i| hit["_type"] }.each do |type, grouped_hits|
25 25 records = type.camelize.constantize
26 26 if options[:includes]
27   - if defined?(NoBrainer::Document) and records < NoBrainer::Document
  27 + if defined?(NoBrainer::Document) && records < NoBrainer::Document
28 28 records = records.preload(options[:includes])
29 29 else
30 30 records = records.includes(options[:includes])
... ... @@ -138,16 +138,16 @@ module Searchkick
138 138 private
139 139  
140 140 def results_query(records, grouped_hits)
141   - if records.respond_to?(:primary_key) and records.primary_key
  141 + if records.respond_to?(:primary_key) && records.primary_key
142 142 # ActiveRecord
143 143 records.where(records.primary_key => grouped_hits.map{|hit| hit["_id"] }).to_a
144   - elsif records.respond_to?(:all) and records.all.respond_to?(:for_ids)
  144 + elsif records.respond_to?(:all) && records.all.respond_to?(:for_ids)
145 145 # Mongoid 2
146 146 records.all.for_ids(grouped_hits.map{|hit| hit["_id"] }).to_a
147 147 elsif records.respond_to?(:queryable)
148 148 # Mongoid 3+
149 149 records.queryable.for_ids(grouped_hits.map{|hit| hit["_id"] }).to_a
150   - elsif records.respond_to?(:unscoped) and records.all.respond_to?(:preload)
  150 + elsif records.respond_to?(:unscoped) && records.all.respond_to?(:preload)
151 151 # Nobrainer
152 152 records.unscoped.where(:id.in => grouped_hits.map{|hit| hit["_id"] }).to_a
153 153 else
... ...
test/sql_test.rb
... ... @@ -312,7 +312,7 @@ class TestSql &lt; Minitest::Test
312 312 end
313 313  
314 314 # TODO see if Mongoid is loaded
315   - unless defined?(Mongoid) or defined?(NoBrainer)
  315 + unless defined?(Mongoid) || defined?(NoBrainer)
316 316 def test_include
317 317 store_names ["Product A"]
318 318 assert Product.search("product", include: [:store]).first.association(:store).loaded?
... ...