Permalink
Browse files

Added index_suffix option - #891

  • Loading branch information...
ankane committed Apr 16, 2017
1 parent 45be88e commit 1f5c350661f9707324be59d9189d03745feb1e3f
Showing with 39 additions and 8 deletions.
  1. +1 −0 CHANGELOG.md
  2. +8 −0 README.md
  3. +7 −0 Rakefile
  4. +1 −1 lib/searchkick.rb
  5. +2 −2 lib/searchkick/model.rb
  6. +8 −0 test/gemfiles/parallel_tests.gemfile
  7. +5 −3 test/index_test.rb
  8. +7 −2 test/test_helper.rb
View
@@ -2,6 +2,7 @@
- Added `avg`, `cardinality`, `max`, `min`, and `sum` aggregations
- Added `load: {dumpable: true}` option
- Added `index_suffix` option
- Accept string for `exclude` option
## 2.2.0
View
@@ -1770,6 +1770,14 @@ product = FactoryGirl.create(:product)
product.reindex(refresh: true)
```
### Parallel Tests
Set:
```ruby
Searchkick.index_suffix = ENV["TEST_ENV_NUMBER"]
```
## Multi-Tenancy
Check out [this great post](https://www.tiagoamaro.com.br/2014/12/11/multi-tenancy-with-searchkick/) on the [Apartment](https://github.com/influitive/apartment) gem. Follow a similar pattern if you use another gem.
View
@@ -1,6 +1,13 @@
require "bundler/gem_tasks"
require "rake/testtask"
begin
require "parallel_tests/tasks"
require "shellwords"
rescue LoadError
# do nothing
end
task default: :test
Rake::TestTask.new do |t|
t.libs << "test"
View
@@ -36,7 +36,7 @@ class DangerousOperation < Error; end
class ImportError < Error; end
class << self
attr_accessor :search_method_name, :wordnet_path, :timeout, :models, :client_options, :redis
attr_accessor :search_method_name, :wordnet_path, :timeout, :models, :client_options, :redis, :index_suffix
attr_writer :client, :env, :search_timeout
attr_reader :aws_credentials
end
View
@@ -21,8 +21,8 @@ def searchkick(**options)
class_variable_set :@@searchkick_klass, self
class_variable_set :@@searchkick_callbacks, callbacks
class_variable_set :@@searchkick_index, options[:index_name] ||
(options[:index_prefix].respond_to?(:call) && proc { [options[:index_prefix].call, model_name.plural, Searchkick.env].compact.join("_") }) ||
[options[:index_prefix], model_name.plural, Searchkick.env].compact.join("_")
(options[:index_prefix].respond_to?(:call) && proc { [options[:index_prefix].call, model_name.plural, Searchkick.env, Searchkick.index_suffix].compact.join("_") }) ||
[options[:index_prefix], model_name.plural, Searchkick.env, Searchkick.index_suffix].compact.join("_")
class << self
def searchkick_search(term = "*", **options, &block)
@@ -0,0 +1,8 @@
source 'https://rubygems.org'
# Specify your gem's dependencies in searchkick.gemspec
gemspec path: "../../"
gem "sqlite3"
gem "activerecord", "~> 5.0.0"
gem "parallel_tests"
View
@@ -7,8 +7,9 @@ def setup
end
def test_clean_indices
old_index = Searchkick::Index.new("products_test_20130801000000000")
different_index = Searchkick::Index.new("items_test_20130801000000000")
suffix = Searchkick.index_suffix ? "_#{Searchkick.index_suffix}" : ""
old_index = Searchkick::Index.new("products_test#{suffix}_20130801000000000")
different_index = Searchkick::Index.new("items_test#{suffix}_20130801000000000")
old_index.delete if old_index.exists?
different_index.delete if different_index.exists?
@@ -25,7 +26,8 @@ def test_clean_indices
end
def test_clean_indices_old_format
old_index = Searchkick::Index.new("products_test_20130801000000")
suffix = Searchkick.index_suffix ? "_#{Searchkick.index_suffix}" : ""
old_index = Searchkick::Index.new("products_test#{suffix}_20130801000000")
old_index.create
Product.searchkick_index.clean_indices
View
@@ -6,11 +6,16 @@
require "active_support/core_ext" if defined?(NoBrainer)
require "active_support/notifications"
Searchkick.index_suffix = ENV["TEST_ENV_NUMBER"]
ENV["RACK_ENV"] = "test"
Minitest::Test = Minitest::Unit::TestCase unless defined?(Minitest::Test)
File.delete("elasticsearch.log") if File.exist?("elasticsearch.log")
if !defined?(ParallelTests) || ParallelTests.first_process?
File.delete("elasticsearch.log") if File.exist?("elasticsearch.log")
end
Searchkick.client.transport.logger = Logger.new("elasticsearch.log")
Searchkick.search_timeout = 5
@@ -466,7 +471,7 @@ class Animal
searchkick \
text_start: [:name],
suggest: [:name],
index_name: -> { "#{name.tableize}-#{Date.today.year}" },
index_name: -> { "#{name.tableize}-#{Date.today.year}#{Searchkick.index_suffix}" },
callbacks: defined?(ActiveJob) ? :async : true
# wordnet: true
end

0 comments on commit 1f5c350

Please sign in to comment.