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