diff --git a/.travis.yml b/.travis.yml index 976d8ee1..3a9b42bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,8 @@ matrix: env: RAILS_VERSION=5.1 SEQUEL_VERSION=5.0 - rvm: 2.6.0 env: RAILS_VERSION=5.2 SEQUEL_VERSION=5.0 + - rvm: 2.7.0 + env: RAILS_VERSION=5.2 SEQUEL_VERSION=5.0 before_install: - wget http://api-key-dealer.herokuapp.com/clients/algolia-keys && chmod +x algolia-keys diff --git a/ChangeLog b/ChangeLog index 44b6d83d..9b7b9745 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ # CHANGELOG +## [1.24.1](https://github.com/algolia/algoliasearch-rails/releases/tag/1.24.1) (2020-07-15) + +**Fixed** + +* Fixes ruby warning 'Proc.new is deprecated' + +## [1.24.0](https://github.com/algolia/algoliasearch-rails/releases/tag/1.24.0) (2020-02-21) + +**Added** + +* Adds indexLanguages in index settings + ## [1.23.2](https://github.com/algolia/algoliasearch-rails/releases/tag/1.23.2) (2019-06-26) **Fixed** diff --git a/README.md b/README.md index a78e0f19..3e1bd875 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Community ForumStack OverflowReport a bug • + FAQSupport

@@ -82,6 +83,8 @@ You can find the full reference on [Algolia's website](https://www.algolia.com/d 1. **[Testing](#testing)** * [Notes](#notes) +1. **[Troubleshooting](#troubleshooting)** + * [Frequently asked questions](#frequently-asked-questions) @@ -1182,3 +1185,11 @@ end +# Troubleshooting + + +## Frequently asked questions + +Encountering an issue? Before reaching out to support, we recommend heading to our [FAQ](https://www.algolia.com/doc/framework-integration/rails/troubleshooting/faq/) where you will find answers for the most common issues and gotchas with the gem. + + diff --git a/lib/algoliasearch-rails.rb b/lib/algoliasearch-rails.rb index 5c1caabc..95736514 100644 --- a/lib/algoliasearch-rails.rb +++ b/lib/algoliasearch-rails.rb @@ -68,7 +68,7 @@ class IndexSettings :disableTypoToleranceOnAttributes, :disableTypoToleranceOnWords, :separatorsToIndex, # Language :ignorePlurals, :removeStopWords, :camelCaseAttributes, :decompoundedAttributes, - :keepDiacriticsOnCharacters, :queryLanguages, + :keepDiacriticsOnCharacters, :queryLanguages, :indexLanguages, # Query Rules :enableRules, # Query Strategy @@ -90,9 +90,9 @@ class IndexSettings end end - def initialize(options, block) + def initialize(options, &block) @options = options - instance_exec(&block) if block + instance_exec(&block) if block_given? end def use_serializer(serializer) @@ -252,12 +252,14 @@ def to_settings settings[:slaves] = additional_indexes.select { |opts, s| opts[:slave] }.map do |opts, s| name = opts[:index_name] name = "#{name}_#{Rails.env.to_s}" if opts[:per_environment] + name = "virtual(#{name})" if opts[:virtual] name end settings.delete(:slaves) if settings[:slaves].empty? settings[:replicas] = additional_indexes.select { |opts, s| opts[:replica] }.map do |opts, s| name = opts[:index_name] name = "#{name}_#{Rails.env.to_s}" if opts[:per_environment] + name = "virtual(#{name})" if opts[:virtual] name end settings.delete(:replicas) if settings[:replicas].empty? @@ -272,7 +274,7 @@ def add_index(index_name, options = {}, &block) @additional_indexes ||= {} raise MixedSlavesAndReplicas.new('Cannot mix slaves and replicas in the same configuration (add_slave is deprecated)') if (options[:slave] && @additional_indexes.any? { |opts, _| opts[:replica] }) || (options[:replica] && @additional_indexes.any? { |opts, _| opts[:slave] }) options[:index_name] = index_name - @additional_indexes[options] = IndexSettings.new(options, Proc.new) + @additional_indexes[options] = IndexSettings.new(options, &block) end def add_replica(index_name, options = {}, &block) @@ -389,7 +391,7 @@ class < algolia_full_const_get(model_name.to_s), :per_page => algoliasearch_settings.get_setting(:hitsPerPage) || 10, :page => 1 }.merge(options) attr_accessor :highlight_result, :snippet_result @@ -607,14 +609,14 @@ def algolia_index_objects(objects, synchronous = false) next if algolia_indexing_disabled?(options) index = algolia_ensure_init(options, settings) next if options[:slave] || options[:replica] - task = index.save_objects(objects.map { |o| settings.get_attributes(o).merge 'objectID' => algolia_object_id_of(o, options) }) + task = index.save_objects(objects.filter { |o| algolia_indexable?(o, options) && !algolia_object_id_of(o, options).blank? }.map { |o| settings.get_attributes(o).merge 'objectID' => algolia_object_id_of(o, options) }) index.wait_task(task["taskID"]) if synchronous || options[:synchronous] end end def algolia_index!(object, synchronous = false) return if algolia_without_auto_index_scope - algolia_configurations.each do |options, settings| + algolia_configurations.map do |options, settings| next if algolia_indexing_disabled?(options) object_id = algolia_object_id_of(object, options) index = algolia_ensure_init(options, settings) @@ -635,7 +637,6 @@ def algolia_index!(object, synchronous = false) end end end - nil end def algolia_remove_from_index!(object, synchronous = false) diff --git a/lib/algoliasearch/version.rb b/lib/algoliasearch/version.rb index e48a07cf..4e855dd6 100644 --- a/lib/algoliasearch/version.rb +++ b/lib/algoliasearch/version.rb @@ -1,3 +1,3 @@ module AlgoliaSearch - VERSION = '1.23.2' + VERSION = '1.24.1' end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 0c88b5e6..28c0fd14 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -110,6 +110,9 @@ create_table :sub_replicas do |t| t.string :name end + create_table :virtual_replicas do |t| + t.string :name + end unless OLD_RAILS create_table :enqueued_objects do |t| t.string :name @@ -433,6 +436,19 @@ class SubReplicas < ActiveRecord::Base end end +class VirtualReplicas < ActiveRecord::Base + include AlgoliaSearch + + algoliasearch :synchronous => true, :force_utf8_encoding => true, :index_name => safe_index_name("VirtualReplica_primary") do + attributesToIndex [:name] + customRanking ["asc(name)"] + + add_replica safe_index_name("VirtualReplica_replica"), virtual: true do + customRanking ["desc(name)"] + end + end +end + class WithSlave < ActiveRecord::Base include AlgoliaSearch @@ -538,7 +554,7 @@ class SerializedObject < ActiveRecord::Base Color.delete_all end - it "Throw an exception if the data is too big" do + it "should throw an exception if the data is too big" do expect { Color.create! :name => 'big' * 100000 }.to raise_error(Algolia::AlgoliaProtocolError) @@ -1190,6 +1206,25 @@ class ForwardToReplicasTwo < ActiveRecord::Base end end +describe "VirtualReplicas" do + before(:all) do + VirtualReplicas.clear_index!(true) + end + + it "setup the replica" do + VirtualReplicas.send(:algolia_configurations).to_a.each do |v| + if v[0][:replica] + expect(v[0][:index_name]).to eq(safe_index_name("VirtualReplica_replica")) + expect(v[0][:virtual]).to eq(true) + expect(v[1].to_settings[:replicas]).to be_nil + else + expect(v[0][:index_name]).to eq(safe_index_name("VirtualReplica_primary")) + expect(v[1].to_settings[:replicas]).to match_array(["virtual(#{safe_index_name("VirtualReplica_replica")})"]) + end + end + end +end + describe "WithSlave" do before(:all) do WithSlave.clear_index!(true)