diff --git a/lib/searchkick/index.rb b/lib/searchkick/index.rb
index b1f8df8..495e0df 100644
--- a/lib/searchkick/index.rb
+++ b/lib/searchkick/index.rb
@@ -100,7 +100,7 @@ module Searchkick
def similar_record(record, options = {})
like_text = retrieve(record).to_hash
- .keep_if { |k, v| !options[:fields] || options[:fields].map(&:to_s).include?(k) }
+ .keep_if { |k, _| !options[:fields] || options[:fields].map(&:to_s).include?(k) }
.values.compact.join(" ")
# TODO deep merge method
@@ -118,9 +118,7 @@ module Searchkick
def search_model(searchkick_klass, term = nil, options = {}, &block)
query = Searchkick::Query.new(searchkick_klass, term, options)
- if block
- block.call(query.body)
- end
+ block.call(query.body) if block
if options[:execute] == false
query
else
@@ -350,9 +348,7 @@ module Searchkick
# synonyms
synonyms = options[:synonyms] || []
- if synonyms.respond_to?(:call)
- synonyms = synonyms.call
- end
+ synonyms = synonyms.call if synonyms.respond_to?(:call)
if synonyms.any?
settings[:analysis][:filter][:searchkick_synonym] = {
@@ -384,7 +380,7 @@ module Searchkick
end
if options[:special_characters] == false
- settings[:analysis][:analyzer].each do |analyzer, analyzer_settings|
+ settings[:analysis][:analyzer].each do |_, analyzer_settings|
analyzer_settings[:filter].reject! { |f| f == "asciifolding" }
end
end
@@ -566,6 +562,5 @@ module Searchkick
obj
end
end
-
end
end
diff --git a/lib/searchkick/logging.rb b/lib/searchkick/logging.rb
index 5c371b7..965980b 100644
--- a/lib/searchkick/logging.rb
+++ b/lib/searchkick/logging.rb
@@ -62,7 +62,8 @@ module Searchkick
end
def self.reset_runtime
- rt, self.runtime = runtime, 0
+ rt = runtime
+ self.runtime = 0
rt
end
@@ -122,7 +123,8 @@ module Searchkick
module ClassMethods
def log_process_action(payload)
- messages, runtime = super, payload[:searchkick_runtime]
+ messages = super
+ runtime = payload[:searchkick_runtime]
messages << ("Searchkick: %.1fms" % runtime.to_f) if runtime.to_f > 0
messages
end
diff --git a/lib/searchkick/model.rb b/lib/searchkick/model.rb
index b7fa8a2..827ab8b 100644
--- a/lib/searchkick/model.rb
+++ b/lib/searchkick/model.rb
@@ -2,7 +2,6 @@ module Searchkick
module Reindex; end # legacy for Searchjoy
module Model
-
def searchkick(options = {})
raise "Only call searchkick once per model" if respond_to?(:searchkick_index)
@@ -94,9 +93,7 @@ module Searchkick
def should_index?
true
end unless method_defined?(:should_index?)
-
end
end
-
end
end
diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb
index 2371604..e2e8fd3 100644
--- a/lib/searchkick/query.rb
+++ b/lib/searchkick/query.rb
@@ -190,11 +190,9 @@ module Searchkick
if boost_by.is_a?(Array)
boost_by = Hash[boost_by.map { |f| [f, {factor: 1}] }]
elsif boost_by.is_a?(Hash)
- multiply_by, boost_by = boost_by.partition { |k,v| v[:boost_mode] == "multiply" }.map{ |i| Hash[i] }
- end
- if options[:boost]
- boost_by[options[:boost]] = {factor: 1}
+ multiply_by, boost_by = boost_by.partition { |_, v| v[:boost_mode] == "multiply" }.map { |i| Hash[i] }
end
+ boost_by[options[:boost]] = {factor: 1} if options[:boost]
custom_filters.concat boost_filters(boost_by, log: true)
multiply_filters.concat boost_filters(multiply_by || {})
@@ -209,12 +207,10 @@ module Searchkick
boost_where.each do |field, value|
if value.is_a?(Array) && value.first.is_a?(Hash)
value.each do |value_factor|
- value, factor = value_factor[:value], value_factor[:factor]
- custom_filters << custom_filter(field, value, factor)
+ custom_filters << custom_filter(field, value_factor[:value], value_factor[:factor])
end
elsif value.is_a?(Hash)
- value, factor = value[:value], value[:factor]
- custom_filters << custom_filter(field, value, factor)
+ custom_filters << custom_filter(field, value[:value], value[:factor])
else
factor = 1000
custom_filters << custom_filter(field, value, factor)
@@ -227,7 +223,7 @@ module Searchkick
if !boost_by_distance[:field] || !boost_by_distance[:origin]
raise ArgumentError, "boost_by_distance requires :field and :origin"
end
- function_params = boost_by_distance.select { |k, v| [:origin, :scale, :offset, :decay].include?(k) }
+ function_params = boost_by_distance.select { |k, _| [:origin, :scale, :offset, :decay].include?(k) }
function_params[:origin] = function_params[:origin].reverse
custom_filters << {
boost_by_distance[:function] => {
@@ -293,9 +289,7 @@ module Searchkick
# facets
if options[:facets]
facets = options[:facets] || {}
- if facets.is_a?(Array) # convert to more advanced syntax
- facets = Hash[facets.map { |f| [f, {}] }]
- end
+ facets = Hash[facets.map { |f| [f, {}] }] if facets.is_a?(Array) # convert to more advanced syntax
payload[:facets] = {}
facets.each do |field, facet_options|
@@ -331,7 +325,7 @@ module Searchkick
# offset is not possible
# http://elasticsearch-users.115913.n3.nabble.com/Is-pagination-possible-in-termsStatsFacet-td3422943.html
- facet_options.deep_merge!(where: options.fetch(:where, {}).reject { |k| k == field } ) if options[:smart_facets] == true
+ facet_options.deep_merge!(where: options.fetch(:where, {}).reject { |k| k == field }) if options[:smart_facets] == true
facet_filters = where_filters(facet_options[:where])
if facet_filters.any?
payload[:facets][field][:facet_filter] = {
@@ -348,9 +342,7 @@ module Searchkick
aggs = options[:aggs]
payload[:aggs] = {}
- if aggs.is_a?(Array) # convert to more advanced syntax
- aggs = aggs.map { |f| [f, {}] }.to_h
- end
+ aggs = aggs.map { |f| [f, {}] }.to_h if aggs.is_a?(Array) # convert to more advanced syntax
aggs.each do |field, agg_options|
size = agg_options[:limit] ? agg_options[:limit] : 100_000
@@ -362,7 +354,7 @@ module Searchkick
}
}
- agg_options.deep_merge!(where: options.fetch(:where, {}).reject { |k| k == field } ) if options[:smart_aggs] == true
+ agg_options.deep_merge!(where: options.fetch(:where, {}).reject { |k| k == field }) if options[:smart_aggs] == true
agg_filters = where_filters(agg_options[:where])
if agg_filters.any?
@@ -441,9 +433,7 @@ module Searchkick
end
# routing
- if options[:routing]
- @routing = options[:routing]
- end
+ @routing = options[:routing] if options[:routing]
end
@body = payload
@@ -539,9 +529,7 @@ module Searchkick
value = {gte: value.first, (value.exclude_end? ? :lt : :lte) => value.last}
end
- if value.is_a?(Array)
- value = {in: value}
- end
+ value = {in: value} if value.is_a?(Array)
if value.is_a?(Hash)
value.each do |op, op_value|
@@ -623,7 +611,7 @@ module Searchkick
def custom_filter(field, value, factor)
{
filter: {
- and: where_filters({field => value})
+ and: where_filters(field => value)
},
boost_factor: factor
}
diff --git a/lib/searchkick/reindex_job.rb b/lib/searchkick/reindex_job.rb
index ffa43ce..2e6448c 100644
--- a/lib/searchkick/reindex_job.rb
+++ b/lib/searchkick/reindex_job.rb
@@ -1,6 +1,5 @@
module Searchkick
class ReindexJob
-
def initialize(klass, id)
@klass = klass
@id = id
@@ -23,6 +22,5 @@ module Searchkick
index.store record
end
end
-
end
end
diff --git a/lib/searchkick/reindex_v2_job.rb b/lib/searchkick/reindex_v2_job.rb
index 689eb10..df5be55 100644
--- a/lib/searchkick/reindex_v2_job.rb
+++ b/lib/searchkick/reindex_v2_job.rb
@@ -19,6 +19,5 @@ module Searchkick
index.store record
end
end
-
end
end
diff --git a/lib/searchkick/results.rb b/lib/searchkick/results.rb
index f18d520..4ecf6b1 100644
--- a/lib/searchkick/results.rb
+++ b/lib/searchkick/results.rb
@@ -26,7 +26,7 @@ module Searchkick
# results can have different types
results = {}
- hits.group_by { |hit, i| hit["_type"] }.each do |type, grouped_hits|
+ hits.group_by { |hit, _| hit["_type"] }.each do |type, grouped_hits|
results[type] = results_query(type.camelize.constantize, grouped_hits).to_a.index_by { |r| r.id.to_s }
end
diff --git a/lib/searchkick/tasks.rb b/lib/searchkick/tasks.rb
index 1c4d05a..e80d151 100644
--- a/lib/searchkick/tasks.rb
+++ b/lib/searchkick/tasks.rb
@@ -1,7 +1,6 @@
require "rake"
namespace :searchkick do
-
desc "reindex model"
task reindex: :environment do
if ENV["CLASS"]
@@ -31,5 +30,4 @@ namespace :searchkick do
end
end
-
end
diff --git a/test/aggs_test.rb b/test/aggs_test.rb
index daeab78..495c0a3 100644
--- a/test/aggs_test.rb
+++ b/test/aggs_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class AggsTest < Minitest::Test
-
def setup
super
store [
@@ -79,5 +78,4 @@ class AggsTest < Minitest::Test
[field, buckets_as_hash(filtered_agg)]
end.to_h
end
-
end
diff --git a/test/autocomplete_test.rb b/test/autocomplete_test.rb
index 807d64f..b31fb6a 100644
--- a/test/autocomplete_test.rb
+++ b/test/autocomplete_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class AutocompleteTest < Minitest::Test
-
def test_autocomplete
store_names ["Hummus"]
assert_search "hum", ["Hummus"], autocomplete: true
@@ -63,5 +62,4 @@ class AutocompleteTest < Minitest::Test
store_names ["hi@example.org"]
assert_search "hi@example.org", ["hi@example.org"], fields: [{name: :exact}]
end
-
end
diff --git a/test/boost_test.rb b/test/boost_test.rb
index 2958b0b..96fe916 100644
--- a/test/boost_test.rb
+++ b/test/boost_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class BoostTest < Minitest::Test
-
# conversions
def test_conversions
@@ -133,5 +132,4 @@ class BoostTest < Minitest::Test
]
assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {field: :location, origin: [37, -122], scale: "1000mi"}
end
-
end
diff --git a/test/facets_test.rb b/test/facets_test.rb
index 1df971a..c15edce 100644
--- a/test/facets_test.rb
+++ b/test/facets_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class FacetsTest < Minitest::Test
-
def setup
skip if elasticsearch2?
super
@@ -79,14 +78,13 @@ class FacetsTest < Minitest::Test
skip if Gem::Version.new(Searchkick.server_version) >= Gem::Version.new("1.4.0")
options = {where: {store_id: 2}, facets: {store_id: {stats: true}}}
facets = Product.search("Product", options).facets["store_id"]["terms"]
- expected_facets_keys = %w[term count total_count min max total mean]
+ expected_facets_keys = %w(term count total_count min max total mean)
assert_equal expected_facets_keys, facets.first.keys
end
protected
- def store_facet(options, facet_key="store_id")
+ def store_facet(options, facet_key = "store_id")
Hash[Product.search("Product", options).facets[facet_key]["terms"].map { |v| [v["term"], v["count"]] }]
end
-
end
diff --git a/test/highlight_test.rb b/test/highlight_test.rb
index 8dc4363..d9a74ff 100644
--- a/test/highlight_test.rb
+++ b/test/highlight_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class HighlightTest < Minitest::Test
-
def test_basic
store_names ["Two Door Cinema Club"]
assert_equal "Two Door Cinema Club", Product.search("cinema", fields: [:name], highlight: true).with_details.first[1][:highlight][:name]
@@ -54,5 +53,4 @@ class HighlightTest < Minitest::Test
}
assert_equal "Two Door Cinema Club", Product.search(json: json).with_details.first[1][:highlight][:"name.analyzed"]
end
-
end
diff --git a/test/index_test.rb b/test/index_test.rb
index c49e503..dd012cf 100644
--- a/test/index_test.rb
+++ b/test/index_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class IndexTest < Minitest::Test
-
def test_clean_indices
old_index = Searchkick::Index.new("products_test_20130801000000000")
different_index = Searchkick::Index.new("items_test_20130801000000000")
@@ -93,7 +92,7 @@ class IndexTest < Minitest::Test
end
def test_unsupported_version
- raises_exception = ->(s) { raise Elasticsearch::Transport::Transport::Error.new("[500] No query registered for [multi_match]") }
+ raises_exception = ->(_) { raise Elasticsearch::Transport::Transport::Error.new("[500] No query registered for [multi_match]") }
Searchkick.client.stub :search, raises_exception do
assert_raises(Searchkick::UnsupportedVersionError) { Product.search("test") }
end
@@ -115,5 +114,4 @@ class IndexTest < Minitest::Test
end
end
-
end
diff --git a/test/inheritance_test.rb b/test/inheritance_test.rb
index 60dd4ba..504fe2a 100644
--- a/test/inheritance_test.rb
+++ b/test/inheritance_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class InheritanceTest < Minitest::Test
-
def test_child_reindex
store_names ["Max"], Cat
assert Dog.reindex
@@ -76,5 +75,4 @@ class InheritanceTest < Minitest::Test
store_names ["Product B"], Animal
assert_search "product", ["Product A", "Product B"], index_name: [Product.searchkick_index.name, Animal.searchkick_index.name], conversions: false
end
-
end
diff --git a/test/match_test.rb b/test/match_test.rb
index a9603d7..95b163b 100644
--- a/test/match_test.rb
+++ b/test/match_test.rb
@@ -3,7 +3,6 @@
require_relative "test_helper"
class MatchTest < Minitest::Test
-
# exact
def test_match
@@ -195,5 +194,4 @@ class MatchTest < Minitest::Test
]
assert_search "almond", []
end
-
end
diff --git a/test/model_test.rb b/test/model_test.rb
index 7f8c453..c7080c3 100644
--- a/test/model_test.rb
+++ b/test/model_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class ModelTest < Minitest::Test
-
def test_disable_callbacks_model
store_names ["product a"]
@@ -34,5 +33,4 @@ class ModelTest < Minitest::Test
assert_search "product", ["product a", "product b"]
end
-
end
diff --git a/test/query_test.rb b/test/query_test.rb
index 7d51e6a..d0d4163 100644
--- a/test/query_test.rb
+++ b/test/query_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class QueryTest < Minitest::Test
-
def test_basic
store_names ["Milk", "Apple"]
query = Product.search("milk", execute: false)
@@ -10,5 +9,4 @@ class QueryTest < Minitest::Test
query.body[:query] = {match_all: {}}
assert_equal ["Apple", "Milk"], query.execute.map(&:name).sort
end
-
end
diff --git a/test/records_test.rb b/test/records_test.rb
index a7f8bd1..d18ade3 100644
--- a/test/records_test.rb
+++ b/test/records_test.rb
@@ -1,10 +1,8 @@
require_relative "test_helper"
class RecordsTest < Minitest::Test
-
def test_records
store_names ["Milk", "Apple"]
assert_equal Product.search("milk").records.where(name: "Milk").count, 1
end
-
end
diff --git a/test/reindex_job_test.rb b/test/reindex_job_test.rb
index 43c28ec..9233ac9 100644
--- a/test/reindex_job_test.rb
+++ b/test/reindex_job_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class ReindexJobTest < Minitest::Test
-
def setup
super
Searchkick.disable_callbacks
@@ -29,5 +28,4 @@ class ReindexJobTest < Minitest::Test
Product.searchkick_index.refresh
assert_search "*", []
end
-
end
diff --git a/test/reindex_v2_job_test.rb b/test/reindex_v2_job_test.rb
index 86f9768..0bf88b0 100644
--- a/test/reindex_v2_job_test.rb
+++ b/test/reindex_v2_job_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class ReindexV2JobTest < Minitest::Test
-
def setup
skip unless defined?(ActiveJob)
super
@@ -30,5 +29,4 @@ class ReindexV2JobTest < Minitest::Test
Product.searchkick_index.refresh
assert_search "*", []
end
-
end
diff --git a/test/routing_test.rb b/test/routing_test.rb
index ca816a6..3b40162 100644
--- a/test/routing_test.rb
+++ b/test/routing_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class RoutingTest < Minitest::Test
-
def test_routing_query
skip if elasticsearch2?
query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false)
@@ -11,7 +10,6 @@ class RoutingTest < Minitest::Test
def test_routing_mappings
skip if elasticsearch2?
index_options = Store.searchkick_index.index_options
- assert_equal index_options[:mappings][:_default_][:_routing], {required: true, path: "name"}
+ assert_equal index_options[:mappings][:_default_][:_routing], required: true, path: "name"
end
-
end
diff --git a/test/similar_test.rb b/test/similar_test.rb
index bd21f02..4a144c1 100644
--- a/test/similar_test.rb
+++ b/test/similar_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class SimilarTest < Minitest::Test
-
def test_similar
store_names ["Annie's Naturals Organic Shiitake & Sesame Dressing"]
assert_search "Annie's Naturals Shiitake & Sesame Vinaigrette", ["Annie's Naturals Organic Shiitake & Sesame Dressing"], similar: true
@@ -16,5 +15,4 @@ class SimilarTest < Minitest::Test
store_names ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"]
assert_order "Lucerne Fat Free Chocolate Milk", ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"], similar: true
end
-
end
diff --git a/test/sql_test.rb b/test/sql_test.rb
index f1c753a..bba778e 100644
--- a/test/sql_test.rb
+++ b/test/sql_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class SqlTest < Minitest::Test
-
def test_limit
store_names ["Product A", "Product B", "Product C", "Product D"]
assert_order "product", ["Product A", "Product B"], order: {name: :asc}, limit: 2
@@ -333,7 +332,7 @@ class SqlTest < Minitest::Test
def test_select
store [{name: "Product A", store_id: 1}]
result = Product.search("product", load: false, select: [:name, :store_id]).first
- assert_equal %w[id name store_id], result.keys.reject { |k| k.start_with?("_") }.sort
+ assert_equal %w(id name store_id), result.keys.reject { |k| k.start_with?("_") }.sort
assert_equal ["Product A"], result.name # this is not great
end
@@ -363,5 +362,4 @@ class SqlTest < Minitest::Test
assert Product.search("product", include: [:store]).first.association(:store).loaded?
end
end
-
end
diff --git a/test/suggest_test.rb b/test/suggest_test.rb
index b0e2258..d586cca 100644
--- a/test/suggest_test.rb
+++ b/test/suggest_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class SuggestTest < Minitest::Test
-
def test_basic
store_names ["Great White Shark", "Hammerhead Shark", "Tiger Shark"]
assert_suggest "How Big is a Tigre Shar", "how big is a tiger shark", fields: [:name]
@@ -78,5 +77,4 @@ class SuggestTest < Minitest::Test
def assert_suggest_all(term, expected, options = {})
assert_equal expected.sort, Product.search(term, options.merge(suggest: true)).suggestions.sort
end
-
end
diff --git a/test/synonyms_test.rb b/test/synonyms_test.rb
index 36b6a23..b4f8f3e 100644
--- a/test/synonyms_test.rb
+++ b/test/synonyms_test.rb
@@ -1,7 +1,6 @@
require_relative "test_helper"
class SynonymsTest < Minitest::Test
-
def test_bleach
store_names ["Clorox Bleach", "Kroger Bleach"]
assert_search "clorox", ["Clorox Bleach", "Kroger Bleach"]
@@ -46,5 +45,4 @@ class SynonymsTest < Minitest::Test
# store_names ["Creature", "Beast", "Dragon"], Animal
# assert_search "animal", ["Creature", "Beast"], {}, Animal
# end
-
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 85374ac..170d582 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -101,7 +101,7 @@ elsif defined?(NoBrainer)
field :color, type: String
field :latitude
field :longitude
- field :description, type: String
+ field :description, type: String
belongs_to :store, validates: false
end
@@ -230,10 +230,10 @@ class Store
mappings: {
store: {
properties: {
- name: {type: "string", analyzer: "keyword"},
+ name: {type: "string", analyzer: "keyword"}
}
}
- }
+ }
end
class Animal
@@ -252,7 +252,6 @@ Store.reindex
Animal.reindex
class Minitest::Test
-
def setup
Product.destroy_all
Store.destroy_all
@@ -284,5 +283,4 @@ class Minitest::Test
def assert_first(term, expected, options = {}, klass = Product)
assert_equal expected, klass.search(term, options).map(&:name).first
end
-
end
--
libgit2 0.21.0