From 596770893cad37114b3d8fce817cb416086ad1ef Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sat, 24 Jan 2015 11:26:38 +1100 Subject: [PATCH 01/23] Removing sql_query_info. No longer used by Sphinx. --- lib/thinking_sphinx/active_record/sql_builder.rb | 8 -------- .../active_record/sql_builder/statement.rb | 10 ---------- lib/thinking_sphinx/active_record/sql_source.rb | 1 - .../active_record/sql_builder_spec.rb | 16 ---------------- .../active_record/sql_source_spec.rb | 8 -------- 5 files changed, 43 deletions(-) diff --git a/lib/thinking_sphinx/active_record/sql_builder.rb b/lib/thinking_sphinx/active_record/sql_builder.rb index f611bb477..974f270de 100644 --- a/lib/thinking_sphinx/active_record/sql_builder.rb +++ b/lib/thinking_sphinx/active_record/sql_builder.rb @@ -16,10 +16,6 @@ def sql_query_range statement.to_query_range_relation.to_sql end - def sql_query_info - statement.to_query_info_relation.to_sql - end - def sql_query_pre query.to_query end @@ -96,10 +92,6 @@ def document_id "#{column} AS #{quoted_alias}" end - def reversed_document_id - "($id - #{source.offset}) / #{config.indices.count}" - end - def range_condition condition = [] condition << "#{quoted_primary_key} BETWEEN $start AND $end" unless source.disable_range? diff --git a/lib/thinking_sphinx/active_record/sql_builder/statement.rb b/lib/thinking_sphinx/active_record/sql_builder/statement.rb index 0c468cfbd..0997de7dc 100644 --- a/lib/thinking_sphinx/active_record/sql_builder/statement.rb +++ b/lib/thinking_sphinx/active_record/sql_builder/statement.rb @@ -20,12 +20,6 @@ def to_query_range_relation scope end - def to_query_info_relation - filter_by_query_info - - scope - end - def to_query_pre filter_by_query_pre @@ -49,10 +43,6 @@ def filter_by_query_range ) end - def filter_by_query_info - @scope = scope.where("#{quoted_primary_key} = #{reversed_document_id}") - end - def filter_by_scopes scope_by_select scope_by_where_clause diff --git a/lib/thinking_sphinx/active_record/sql_source.rb b/lib/thinking_sphinx/active_record/sql_source.rb index 6ac56227a..faa1fe6eb 100644 --- a/lib/thinking_sphinx/active_record/sql_source.rb +++ b/lib/thinking_sphinx/active_record/sql_source.rb @@ -118,7 +118,6 @@ def build_sql_fields def build_sql_query @sql_query = builder.sql_query @sql_query_range ||= builder.sql_query_range - @sql_query_info ||= builder.sql_query_info @sql_query_pre += builder.sql_query_pre @sql_query_post_index += builder.sql_query_post_index end diff --git a/spec/thinking_sphinx/active_record/sql_builder_spec.rb b/spec/thinking_sphinx/active_record/sql_builder_spec.rb index c7f853b0f..e6fa51aa2 100644 --- a/spec/thinking_sphinx/active_record/sql_builder_spec.rb +++ b/spec/thinking_sphinx/active_record/sql_builder_spec.rb @@ -469,22 +469,6 @@ end end - describe 'sql_query_info' do - it "filters on the reversed document id" do - relation.should_receive(:where). - with("`users`.`id` = ($id - #{source.offset}) / #{indices.count}"). - and_return(relation) - - builder.sql_query_info - end - - it "returns the generated SQL query" do - relation.stub(:to_sql).and_return('SELECT * FROM people WHERE id = $id') - - builder.sql_query_info.should == 'SELECT * FROM people WHERE id = $id' - end - end - describe 'sql_query_post_index' do let(:processor) { double('processor', :reset_query => 'RESET DELTAS') } diff --git a/spec/thinking_sphinx/active_record/sql_source_spec.rb b/spec/thinking_sphinx/active_record/sql_source_spec.rb index b131033a6..a2f1bdc12 100644 --- a/spec/thinking_sphinx/active_record/sql_source_spec.rb +++ b/spec/thinking_sphinx/active_record/sql_source_spec.rb @@ -186,14 +186,6 @@ source.sql_query_range.should == 'select 0, 10 from table' end - it "uses the builder's sql_query_info value" do - builder.stub! :sql_query_info => 'select * from table where id = ?' - - source.render - - source.sql_query_info.should == 'select * from table where id = ?' - end - it "appends the builder's sql_query_pre value" do builder.stub! :sql_query_pre => ['Change Setting'] From 431f66e66d309c1bd4e10b63116a7daf51a56a16 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sat, 24 Jan 2015 11:26:57 +1100 Subject: [PATCH 02/23] Fix association creation. MacroReflection exists in Rails 4.1. --- lib/thinking_sphinx/active_record/filter_reflection.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/thinking_sphinx/active_record/filter_reflection.rb b/lib/thinking_sphinx/active_record/filter_reflection.rb index d2dff4845..54e3785cd 100644 --- a/lib/thinking_sphinx/active_record/filter_reflection.rb +++ b/lib/thinking_sphinx/active_record/filter_reflection.rb @@ -6,8 +6,9 @@ class ThinkingSphinx::ActiveRecord::FilterReflection def self.call(reflection, name, class_name) filter = new(reflection, class_name) klass = reflection.class + arity = klass.instance_method(:initialize).arity - if defined?(ActiveRecord::Reflection::MacroReflection) + if defined?(ActiveRecord::Reflection::MacroReflection) && arity == 4 klass.new name, filter.scope, filter.options, reflection.active_record elsif reflection.respond_to?(:scope) klass.new reflection.macro, name, filter.scope, filter.options, From 6c6d80662883243b93a2d36483c23daee1b2f36e Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sat, 24 Jan 2015 11:29:46 +1100 Subject: [PATCH 03/23] Remove default charset_type option. No longer required for Sphinx 2.2. --- lib/thinking_sphinx/core/index.rb | 1 - spec/acceptance/excerpts_spec.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/thinking_sphinx/core/index.rb b/lib/thinking_sphinx/core/index.rb index 0a9d1ad22..cee129e65 100644 --- a/lib/thinking_sphinx/core/index.rb +++ b/lib/thinking_sphinx/core/index.rb @@ -10,7 +10,6 @@ module ThinkingSphinx::Core::Index def initialize(reference, options = {}) @reference = reference.to_sym @docinfo = :extern - @charset_type = 'utf-8' @options = options @offset = config.next_offset(options[:offset_as] || reference) @type = 'plain' diff --git a/spec/acceptance/excerpts_spec.rb b/spec/acceptance/excerpts_spec.rb index abc721fc0..983ec0588 100644 --- a/spec/acceptance/excerpts_spec.rb +++ b/spec/acceptance/excerpts_spec.rb @@ -23,7 +23,7 @@ search.first.excerpts.title. should == 'Война и миръ' - end + end if ENV['SPHINX_VERSION'].try :[], /2.2.\d/ it "does not include class names in excerpts" do Book.create! :title => 'The Graveyard Book' From a05b21533c33a443518d4f698501b08667cf72d0 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sat, 24 Jan 2015 11:37:28 +1100 Subject: [PATCH 04/23] Fixing tests for filtered reflection arity check. --- spec/thinking_sphinx/active_record/filter_reflection_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/thinking_sphinx/active_record/filter_reflection_spec.rb b/spec/thinking_sphinx/active_record/filter_reflection_spec.rb index 0bef35593..148182c8c 100644 --- a/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +++ b/spec/thinking_sphinx/active_record/filter_reflection_spec.rb @@ -7,7 +7,9 @@ :foreign_type => :foo_type, :class => reflection_klass) } let(:options) { {:polymorphic => true} } let(:filtered_reflection) { double 'filtered reflection' } - let(:reflection_klass) { double :new => filtered_reflection } + let(:reflection_klass) { double :new => filtered_reflection, + :instance_method => initialize_method } + let(:initialize_method) { double :arity => 4 } before :each do reflection.active_record.stub_chain(:connection, :quote_column_name). From 5401c39bec8c646e9254779277ef23a1f864a80d Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sat, 24 Jan 2015 13:13:48 +1100 Subject: [PATCH 05/23] Escape table names --- lib/thinking_sphinx/active_record/column_sql_presenter.rb | 2 +- spec/acceptance/specifying_sql_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/thinking_sphinx/active_record/column_sql_presenter.rb b/lib/thinking_sphinx/active_record/column_sql_presenter.rb index c0b47f54c..70a2ba1c2 100644 --- a/lib/thinking_sphinx/active_record/column_sql_presenter.rb +++ b/lib/thinking_sphinx/active_record/column_sql_presenter.rb @@ -13,7 +13,7 @@ def with_table return __name if string? return nil unless exists? - "#{associations.alias_for(__stack)}.#{adapter.quote __name}" + "#{adapter.quote associations.alias_for(__stack)}.#{adapter.quote __name}" end private diff --git a/spec/acceptance/specifying_sql_spec.rb b/spec/acceptance/specifying_sql_spec.rb index 234bb546a..afa3f00e3 100644 --- a/spec/acceptance/specifying_sql_spec.rb +++ b/spec/acceptance/specifying_sql_spec.rb @@ -125,7 +125,7 @@ query = index.sources.first.sql_query query.should match(/LEFT OUTER JOIN .articles. ON .articles.\..id. = .events.\..eventable_id. AND .events.\..eventable_type. = 'Article'/) query.should match(/LEFT OUTER JOIN .books. ON .books.\..id. = .events.\..eventable_id. AND .events.\..eventable_type. = 'Book'/) - query.should match(/articles\..title., books\..title./) + query.should match(/.articles.\..title., .books.\..title./) end it "concatenates references that have column" do @@ -139,7 +139,7 @@ query = index.sources.first.sql_query query.should match(/LEFT OUTER JOIN .articles. ON .articles.\..id. = .events.\..eventable_id. AND .events.\..eventable_type. = 'Article'/) query.should_not match(/articles\..title., users\..title./) - query.should match(/articles\..title./) + query.should match(/.articles.\..title./) end it "respects deeper associations through polymorphic joins" do @@ -153,7 +153,7 @@ query = index.sources.first.sql_query query.should match(/LEFT OUTER JOIN .articles. ON .articles.\..id. = .events.\..eventable_id. AND .events.\..eventable_type. = 'Article'/) query.should match(/LEFT OUTER JOIN .users. ON .users.\..id. = .articles.\..user_id./) - query.should match(/users\..name./) + query.should match(/.users.\..name./) end end From 6b3a6cde22c4d0f9674f17bfbdb0fc0319534a18 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Wed, 6 Nov 2013 04:14:27 -0700 Subject: [PATCH 06/23] fix website URL in gemspec --- thinking-sphinx.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thinking-sphinx.gemspec b/thinking-sphinx.gemspec index 06a43ec62..45d2f125c 100644 --- a/thinking-sphinx.gemspec +++ b/thinking-sphinx.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.authors = ["Pat Allan"] s.email = ["pat@freelancing-gods.com"] - s.homepage = 'http://pat.github.io/thinking-sphinx/' + s.homepage = 'https://pat.github.io/thinking-sphinx/' s.summary = 'A smart wrapper over Sphinx for ActiveRecord' s.description = %Q{An intelligent layer for ActiveRecord (via Rails and Sinatra) for the Sphinx full-text search tool.} s.license = 'MIT' From 464e62432827deb5bc1efa9614d3b0aedda1ac51 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 8 Feb 2015 15:24:50 +1100 Subject: [PATCH 07/23] Don't presume database settings are symbols. ActiveRecord 4.2 now uses strings consistently. Closes #885. --- lib/thinking_sphinx/active_record/interpreter.rb | 4 ++-- spec/thinking_sphinx/active_record/interpreter_spec.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/thinking_sphinx/active_record/interpreter.rb b/lib/thinking_sphinx/active_record/interpreter.rb index 25652d344..fd8dfec60 100644 --- a/lib/thinking_sphinx/active_record/interpreter.rb +++ b/lib/thinking_sphinx/active_record/interpreter.rb @@ -39,10 +39,10 @@ def sanitize_sql(*arguments) end def set_database(hash_or_key) - configuration = hash_or_key.is_a?(::Hash) ? hash_or_key.symbolize_keys : + configuration = hash_or_key.is_a?(::Hash) ? hash_or_key : ::ActiveRecord::Base.configurations[hash_or_key.to_s] - __source.set_database_settings configuration + __source.set_database_settings configuration.symbolize_keys end def set_property(properties) diff --git a/spec/thinking_sphinx/active_record/interpreter_spec.rb b/spec/thinking_sphinx/active_record/interpreter_spec.rb index 3b497ff74..6559055d4 100644 --- a/spec/thinking_sphinx/active_record/interpreter_spec.rb +++ b/spec/thinking_sphinx/active_record/interpreter_spec.rb @@ -223,7 +223,7 @@ source.stub :set_database_settings => true stub_const 'ActiveRecord::Base', - double(:configurations => {'other' => {:baz => :qux}}) + double(:configurations => {'other' => {'baz' => 'qux'}}) end it "sends through a hash if provided" do @@ -233,13 +233,13 @@ end it "finds the environment settings if given a string key" do - source.should_receive(:set_database_settings).with(:baz => :qux) + source.should_receive(:set_database_settings).with(:baz => 'qux') instance.set_database 'other' end it "finds the environment settings if given a symbol key" do - source.should_receive(:set_database_settings).with(:baz => :qux) + source.should_receive(:set_database_settings).with(:baz => 'qux') instance.set_database :other end From 6669a89dfe1b0edf146e85560e0c6b6306c6ba40 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 8 Feb 2015 15:30:49 +1100 Subject: [PATCH 08/23] minimal_group_by setting is respected in config/thinking_sphinx.yml. --- .../active_record/sql_builder/statement.rb | 8 ++- .../active_record/sql_builder_spec.rb | 49 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/thinking_sphinx/active_record/sql_builder/statement.rb b/lib/thinking_sphinx/active_record/sql_builder/statement.rb index 0997de7dc..71d7e15eb 100644 --- a/lib/thinking_sphinx/active_record/sql_builder/statement.rb +++ b/lib/thinking_sphinx/active_record/sql_builder/statement.rb @@ -130,10 +130,16 @@ def group_clause builder.compose( presenters_to_group(field_presenters), presenters_to_group(attribute_presenters) - ) unless source.options[:minimal_group_by?] + ) unless minimal_group_by? builder.compose(groupings).separated end + + def minimal_group_by? + source.options[:minimal_group_by?] || + config.settings['minimal_group_by?'] || + config.settings['minimal_group_by'] + end end end end diff --git a/spec/thinking_sphinx/active_record/sql_builder_spec.rb b/spec/thinking_sphinx/active_record/sql_builder_spec.rb index e6fa51aa2..7cdda386b 100644 --- a/spec/thinking_sphinx/active_record/sql_builder_spec.rb +++ b/spec/thinking_sphinx/active_record/sql_builder_spec.rb @@ -415,6 +415,55 @@ end end + context 'group by shortcut in global configuration' do + before :each do + config.settings['minimal_group_by'] = true + end + + it "groups by the primary key" do + relation.should_receive(:group) do |string| + string.should match(/"users"."id"/) + relation + end + + builder.sql_query + end + + it "does not group by fields" do + source.fields << double('field') + + relation.should_receive(:group) do |string| + string.should_not match(/"name"/) + relation + end + + builder.sql_query + end + + it "does not group by attributes" do + source.attributes << double('attribute') + presenter.stub!(:to_group => '"created_at"') + + relation.should_receive(:group) do |string| + string.should_not match(/"created_at"/) + relation + end + + builder.sql_query + end + + it "groups by source groupings" do + source.groupings << '"latitude"' + + relation.should_receive(:group) do |string| + string.should match(/"latitude"/) + relation + end + + builder.sql_query + end + end + context 'STI model' do before :each do model.column_names << 'type' From c38d6e8c582495af5b5cba29388f2b4077ed72b9 Mon Sep 17 00:00:00 2001 From: exAspArk Date: Thu, 29 Jan 2015 11:58:39 +0300 Subject: [PATCH 09/23] unlock file only if it's locked --- lib/thinking_sphinx/guard/file.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/thinking_sphinx/guard/file.rb b/lib/thinking_sphinx/guard/file.rb index a1509571c..9d48a681a 100644 --- a/lib/thinking_sphinx/guard/file.rb +++ b/lib/thinking_sphinx/guard/file.rb @@ -21,6 +21,6 @@ def path end def unlock - FileUtils.rm path + FileUtils.rm(path) if locked? end end From 2b7d151a1b11690e19e0bd44cde6df9298318a2e Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 15 Feb 2015 15:24:45 +1100 Subject: [PATCH 10/23] Rails 3.2 and 4.0 quote table names for us. --- .../active_record/column_sql_presenter.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/thinking_sphinx/active_record/column_sql_presenter.rb b/lib/thinking_sphinx/active_record/column_sql_presenter.rb index 70a2ba1c2..66d678280 100644 --- a/lib/thinking_sphinx/active_record/column_sql_presenter.rb +++ b/lib/thinking_sphinx/active_record/column_sql_presenter.rb @@ -13,7 +13,10 @@ def with_table return __name if string? return nil unless exists? - "#{adapter.quote associations.alias_for(__stack)}.#{adapter.quote __name}" + table = associations.alias_for __stack + table = adapter.quote table if escape_table? + + "#{table}.#{adapter.quote __name}" end private @@ -22,6 +25,13 @@ def with_table delegate :__stack, :__name, :string?, :to => :column + def escape_table? + return false if version::MAJOR <= 3 + return true if version::MAJOR >= 5 + + version::MINOR >= 1 + end + def exists? path.model.column_names.include?(column.__name.to_s) rescue Joiner::AssociationNotFound @@ -31,4 +41,8 @@ def exists? def path Joiner::Path.new model, column.__stack end + + def version + ActiveRecord::VERSION + end end From 529790d00aac9ce50c30e628ca686d0f9f3d1ee2 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 15 Feb 2015 15:52:12 +1100 Subject: [PATCH 11/23] Updating Appraisal. --- gemfiles/rails_3_2.gemfile | 10 +++++----- gemfiles/rails_4_0.gemfile | 10 +++++----- gemfiles/rails_4_1.gemfile | 10 +++++----- gemfiles/rails_4_2.gemfile | 10 +++++----- thinking-sphinx.gemspec | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/gemfiles/rails_3_2.gemfile b/gemfiles/rails_3_2.gemfile index 6e8bfa3bf..56b8bfef4 100644 --- a/gemfiles/rails_3_2.gemfile +++ b/gemfiles/rails_3_2.gemfile @@ -2,10 +2,10 @@ source "https://rubygems.org" -gem "mysql2", "~> 0.3.12b4", :platform=>:ruby -gem "pg", "~> 0.16.0", :platform=>:ruby -gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform=>:jruby -gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform=>:jruby +gem "mysql2", "~> 0.3.12b4", :platform => :ruby +gem "pg", "~> 0.16.0", :platform => :ruby +gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby +gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby gem "rails", "~> 3.2.21" -gemspec :path=>"../" \ No newline at end of file +gemspec :path => "../" diff --git a/gemfiles/rails_4_0.gemfile b/gemfiles/rails_4_0.gemfile index 7b8dfd189..d1ed7fd27 100644 --- a/gemfiles/rails_4_0.gemfile +++ b/gemfiles/rails_4_0.gemfile @@ -2,10 +2,10 @@ source "https://rubygems.org" -gem "mysql2", "~> 0.3.12b4", :platform=>:ruby -gem "pg", "~> 0.16.0", :platform=>:ruby -gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform=>:jruby -gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform=>:jruby +gem "mysql2", "~> 0.3.12b4", :platform => :ruby +gem "pg", "~> 0.16.0", :platform => :ruby +gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby +gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby gem "rails", "~> 4.0.12" -gemspec :path=>"../" \ No newline at end of file +gemspec :path => "../" diff --git a/gemfiles/rails_4_1.gemfile b/gemfiles/rails_4_1.gemfile index f79b9af5d..46c56fe9f 100644 --- a/gemfiles/rails_4_1.gemfile +++ b/gemfiles/rails_4_1.gemfile @@ -2,10 +2,10 @@ source "https://rubygems.org" -gem "mysql2", "~> 0.3.12b4", :platform=>:ruby -gem "pg", "~> 0.16.0", :platform=>:ruby -gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform=>:jruby -gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform=>:jruby +gem "mysql2", "~> 0.3.12b4", :platform => :ruby +gem "pg", "~> 0.16.0", :platform => :ruby +gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby +gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby gem "rails", "~> 4.1.8" -gemspec :path=>"../" \ No newline at end of file +gemspec :path => "../" diff --git a/gemfiles/rails_4_2.gemfile b/gemfiles/rails_4_2.gemfile index 7bf8eb808..8ada8d7a4 100644 --- a/gemfiles/rails_4_2.gemfile +++ b/gemfiles/rails_4_2.gemfile @@ -2,10 +2,10 @@ source "https://rubygems.org" -gem "mysql2", "~> 0.3.12b4", :platform=>:ruby -gem "pg", "~> 0.16.0", :platform=>:ruby -gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform=>:jruby -gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform=>:jruby +gem "mysql2", "~> 0.3.12b4", :platform => :ruby +gem "pg", "~> 0.16.0", :platform => :ruby +gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby +gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby gem "rails", "~> 4.2.0" -gemspec :path=>"../" \ No newline at end of file +gemspec :path => "../" diff --git a/thinking-sphinx.gemspec b/thinking-sphinx.gemspec index 45d2f125c..e136099ee 100644 --- a/thinking-sphinx.gemspec +++ b/thinking-sphinx.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'innertube', '>= 1.0.2' s.add_runtime_dependency 'riddle', '>= 1.5.11' - s.add_development_dependency 'appraisal', '~> 0.5.2' + s.add_development_dependency 'appraisal', '~> 1.0.2' s.add_development_dependency 'combustion', '~> 0.4.0' s.add_development_dependency 'database_cleaner', '~> 1.2.0' s.add_development_dependency 'rspec', '~> 2.13.0' From e5f7af50defb453b45acb25dc2c1c2b587570337 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 15 Feb 2015 15:52:51 +1100 Subject: [PATCH 12/23] Use Appraisal to run each gemfile. Drops Travis' matrix down a bit. --- .travis.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index fa3722781..e37c7ec2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,12 @@ rvm: - jruby-19mode before_install: - gem update --system + - gem install bundler before_script: - "mysql -e 'create database thinking_sphinx;' > /dev/null" - "psql -c 'create database thinking_sphinx;' -U postgres >/dev/null" + - bundle exec appraisal install +script: bundle exec appraisal rspec env: - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.0.10/bin/ SPHINX_VERSION=2.0.10 - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.0.10/bin/ SPHINX_VERSION=2.0.10 @@ -16,8 +19,3 @@ env: - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.1.8/bin/ SPHINX_VERSION=2.1.8 - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.2.2-beta/bin/ SPHINX_VERSION=2.2.2 - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.2.2-beta/bin/ SPHINX_VERSION=2.2.2 -gemfile: - - gemfiles/rails_3_2.gemfile - - gemfiles/rails_4_0.gemfile - - gemfiles/rails_4_1.gemfile - - gemfiles/rails_4_2.gemfile From ad5c27794f121c3299e03dd61ba01c1aa2ff0bd9 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 15 Feb 2015 15:53:20 +1100 Subject: [PATCH 13/23] Rails 3.2 update_attribute doesn't fire callbacks. --- spec/acceptance/big_integers_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/big_integers_spec.rb b/spec/acceptance/big_integers_spec.rb index 2106aaa98..841e4142a 100644 --- a/spec/acceptance/big_integers_spec.rb +++ b/spec/acceptance/big_integers_spec.rb @@ -50,7 +50,7 @@ context 'with Real-Time' do it 'handles large 32 bit integers with an offset multiplier' do product = Product.create! :name => "Widget" - product.update_attribute :id, 980190962 + product.update_attributes :id => 980190962 expect( Product.search('widget', :indices => ['product_core']).to_a ).to eq([product]) From b9a0535f032ad5e27fec4ba9c81f91a9f05fd3f6 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 15 Feb 2015 15:53:54 +1100 Subject: [PATCH 14/23] Don't use polymorphic associations and Rails 3.2. At least, don't use them in your Thinking Sphinx indices. --- README.textile | 2 ++ spec/acceptance/specifying_sql_spec.rb | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.textile b/README.textile index e2a8c16bd..77fe082cc 100644 --- a/README.textile +++ b/README.textile @@ -44,6 +44,8 @@ h3. Rails and ActiveRecord Currently Thinking Sphinx 3 is built to support Rails/ActiveRecord 3.2 or newer. If you're using Sinatra and ActiveRecord instead of Rails, that's fine - just make sure you add the @:require => 'thinking_sphinx/sinatra'@ option when listing @thinking-sphinx@ in your Gemfile. +Please note that if you're referring to polymorphic associations in your index definitions, you'll want to be using Rails/ActiveRecord 4.0 or newer. Supporting polymorphic associations and Rails/ActiveRecord 3.2 is problematic, and likely will not be addressed in the future. + If you want ActiveRecord 3.1 support, then refer to the 3.0.x releases of Thinking Sphinx. Anything older than that, then you're stuck with Thinking Sphinx v2.x (for Rails/ActiveRecord 3.0) or v1.x (Rails 2.3). Please note that these older versions are no longer actively supported. h3. Ruby diff --git a/spec/acceptance/specifying_sql_spec.rb b/spec/acceptance/specifying_sql_spec.rb index afa3f00e3..a8d72cda2 100644 --- a/spec/acceptance/specifying_sql_spec.rb +++ b/spec/acceptance/specifying_sql_spec.rb @@ -126,7 +126,7 @@ query.should match(/LEFT OUTER JOIN .articles. ON .articles.\..id. = .events.\..eventable_id. AND .events.\..eventable_type. = 'Article'/) query.should match(/LEFT OUTER JOIN .books. ON .books.\..id. = .events.\..eventable_id. AND .events.\..eventable_type. = 'Book'/) query.should match(/.articles.\..title., .books.\..title./) - end + end if ActiveRecord::VERSION::MAJOR > 3 it "concatenates references that have column" do index = ThinkingSphinx::ActiveRecord::Index.new(:event) @@ -140,7 +140,7 @@ query.should match(/LEFT OUTER JOIN .articles. ON .articles.\..id. = .events.\..eventable_id. AND .events.\..eventable_type. = 'Article'/) query.should_not match(/articles\..title., users\..title./) query.should match(/.articles.\..title./) - end + end if ActiveRecord::VERSION::MAJOR > 3 it "respects deeper associations through polymorphic joins" do index = ThinkingSphinx::ActiveRecord::Index.new(:event) @@ -155,7 +155,7 @@ query.should match(/LEFT OUTER JOIN .users. ON .users.\..id. = .articles.\..user_id./) query.should match(/.users.\..name./) end -end +end if ActiveRecord::VERSION::MAJOR > 3 describe 'separate queries for MVAs' do let(:index) { ThinkingSphinx::ActiveRecord::Index.new(:article) } From d698c9d33db46e21ea4b5ea9eb1600c2708ac25f Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 15 Feb 2015 15:54:36 +1100 Subject: [PATCH 15/23] HABTM queries don't work in Rails 3.2 It's a frustrating feature as it is. Sorry Rails 3.2, you're on the way out anyway. --- spec/acceptance/specifying_sql_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/specifying_sql_spec.rb b/spec/acceptance/specifying_sql_spec.rb index a8d72cda2..255dfb170 100644 --- a/spec/acceptance/specifying_sql_spec.rb +++ b/spec/acceptance/specifying_sql_spec.rb @@ -244,7 +244,7 @@ declaration.should == 'uint genre_ids from query' query.should match(/^SELECT .books_genres.\..book_id. \* #{count} \+ #{source.offset} AS .id., .books_genres.\..genre_id. AS .genre_ids. FROM .books_genres.\s?$/) - end + end if ActiveRecord::VERSION::MAJOR > 3 it "generates an appropriate range SQL queries for an MVA" do index.definition_block = Proc.new { @@ -297,7 +297,7 @@ declaration.should == 'uint genre_ids from ranged-query' query.should match(/^SELECT .books_genres.\..book_id. \* #{count} \+ #{source.offset} AS .id., .books_genres.\..genre_id. AS .genre_ids. FROM .books_genres. WHERE \(.books_genres.\..book_id. BETWEEN \$start AND \$end\)$/) range.should match(/^SELECT MIN\(.books_genres.\..book_id.\), MAX\(.books_genres.\..book_id.\) FROM .books_genres.$/) - end + end if ActiveRecord::VERSION::MAJOR > 3 it "respects custom SQL snippets as the query value" do index.definition_block = Proc.new { From c9ce59cad1b30fb79d009a2a8cf792baf799572b Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 15 Feb 2015 16:30:27 +1100 Subject: [PATCH 16/23] Quote if not quoted. Check for quote characters - we're limited to two database types, so this *should* be reasonably reliable. --- .../active_record/column_sql_presenter.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/thinking_sphinx/active_record/column_sql_presenter.rb b/lib/thinking_sphinx/active_record/column_sql_presenter.rb index 66d678280..145a53c00 100644 --- a/lib/thinking_sphinx/active_record/column_sql_presenter.rb +++ b/lib/thinking_sphinx/active_record/column_sql_presenter.rb @@ -13,10 +13,9 @@ def with_table return __name if string? return nil unless exists? - table = associations.alias_for __stack - table = adapter.quote table if escape_table? + quoted_table = escape_table? ? adapter.quote(table) : table - "#{table}.#{adapter.quote __name}" + "#{quoted_table}.#{adapter.quote __name}" end private @@ -26,10 +25,7 @@ def with_table delegate :__stack, :__name, :string?, :to => :column def escape_table? - return false if version::MAJOR <= 3 - return true if version::MAJOR >= 5 - - version::MINOR >= 1 + table[/[`"]/].nil? end def exists? @@ -42,6 +38,10 @@ def path Joiner::Path.new model, column.__stack end + def table + associations.alias_for __stack + end + def version ActiveRecord::VERSION end From 61d4d0f18da4d4217bb524128f495f51fff0cb90 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 15 Feb 2015 18:00:20 +1100 Subject: [PATCH 17/23] Updating Sphinx versions for Travis. --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e37c7ec2c..edf0f7329 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ script: bundle exec appraisal rspec env: - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.0.10/bin/ SPHINX_VERSION=2.0.10 - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.0.10/bin/ SPHINX_VERSION=2.0.10 - - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.1.8/bin/ SPHINX_VERSION=2.1.8 - - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.1.8/bin/ SPHINX_VERSION=2.1.8 - - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.2.2-beta/bin/ SPHINX_VERSION=2.2.2 - - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.2.2-beta/bin/ SPHINX_VERSION=2.2.2 + - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.1.9/bin/ SPHINX_VERSION=2.1.9 + - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.1.9/bin/ SPHINX_VERSION=2.1.9 + - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.2.6/bin/ SPHINX_VERSION=2.2.6 + - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.2.6/bin/ SPHINX_VERSION=2.2.6 From f8d33cab352ad06df460b9abe63eb5e613841f6c Mon Sep 17 00:00:00 2001 From: Daniel Vandersluis Date: Tue, 17 Feb 2015 10:42:07 -0500 Subject: [PATCH 18/23] Add JSON as a Sphinx type --- .../active_record/attribute/sphinx_presenter.rb | 3 ++- spec/thinking_sphinx/active_record/sql_source_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb b/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb index d253f111c..d33980d52 100644 --- a/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb +++ b/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb @@ -7,7 +7,8 @@ class ThinkingSphinx::ActiveRecord::Attribute::SphinxPresenter :string => :string, :bigint => :bigint, :ordinal => :str2ordinal, - :wordcount => :str2wordcount + :wordcount => :str2wordcount, + :json => :json } def initialize(attribute, source) diff --git a/spec/thinking_sphinx/active_record/sql_source_spec.rb b/spec/thinking_sphinx/active_record/sql_source_spec.rb index a2f1bdc12..2616707ac 100644 --- a/spec/thinking_sphinx/active_record/sql_source_spec.rb +++ b/spec/thinking_sphinx/active_record/sql_source_spec.rb @@ -325,6 +325,15 @@ source.sql_attr_str2wordcount.should include('name') end + it "adds json attributes to sql_attr_json" do + source.attributes << double('attribute') + presenter.stub :declaration => 'json', :collection_type => :json + + source.render + + source.sql_attr_json.should include('json') + end + it "adds relevant settings from thinking_sphinx.yml" do config.settings['mysql_ssl_cert'] = 'foo.cert' config.settings['morphology'] = 'stem_en' # should be ignored From 55d818f3d238d6e290265c7f0575fe880ea3ac50 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Tue, 24 Mar 2015 10:07:18 +1100 Subject: [PATCH 19/23] Link up JSON attribute type. --- spec/thinking_sphinx/active_record/attribute/type_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/thinking_sphinx/active_record/attribute/type_spec.rb b/spec/thinking_sphinx/active_record/attribute/type_spec.rb index 6be290190..19a6eeb06 100644 --- a/spec/thinking_sphinx/active_record/attribute/type_spec.rb +++ b/spec/thinking_sphinx/active_record/attribute/type_spec.rb @@ -139,6 +139,12 @@ class Attribute; end type.type.should == :bigint end + it "detects JSON" do + db_column.stub :type => :json + + type.type.should == :json + end + it "respects provided type setting" do attribute.options[:type] = :timestamp From 7137fb5775f38f54fdcd7a97211abe3bcd7c2415 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sat, 28 Mar 2015 11:49:47 +1100 Subject: [PATCH 20/23] Adding contributor code of conduct. --- README.textile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.textile b/README.textile index 77fe082cc..1d67b23d0 100644 --- a/README.textile +++ b/README.textile @@ -60,6 +60,8 @@ MySQL 5.x and Postgres 8.4 or better are supported. h2. Contributing +Please note that this project now has a "Contributor Code of Conduct":http://contributor-covenant.org/version/1/0/0/. By participating in this project you agree to abide by its terms. + To contribute, clone this repository and have a good look through the specs - you'll notice the distinction between acceptance tests that actually use Sphinx and go through the full stack, and unit tests (everything else) which use liberal test doubles to ensure they're only testing the behaviour of the class in question. I've found this leads to far better code design. All development is done on the @develop@ branch; please base any pull requests off of that branch. Please write the tests and then the code to get them passing, and send through a pull request. From a9a78dafc48cfc24dc1c3be7bddefe8bec8c96d7 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Tue, 28 Apr 2015 16:16:14 +1000 Subject: [PATCH 21/23] Kaminari expects prev_page, not previous_page. --- lib/thinking_sphinx/masks/pagination_mask.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/thinking_sphinx/masks/pagination_mask.rb b/lib/thinking_sphinx/masks/pagination_mask.rb index c215e3d75..fe55b0a48 100644 --- a/lib/thinking_sphinx/masks/pagination_mask.rb +++ b/lib/thinking_sphinx/masks/pagination_mask.rb @@ -37,6 +37,8 @@ def previous_page search.current_page == 1 ? nil : search.current_page - 1 end + alias_method :prev_page, :previous_page + def total_entries search.meta['total_found'].to_i end From 8309face3be5d2984d9d81ec748d210bf74126e5 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Mon, 1 Jun 2015 22:08:32 +1000 Subject: [PATCH 22/23] Updating HISTORY file with post-3.1.3 changes. --- HISTORY | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/HISTORY b/HISTORY index e1d552b9e..c696802fe 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,16 @@ +Edge: +* [FIX] Kaminari expects prev_page to be available. +* [CHANGE] Add a contributor code of conduct. +* [FEATURE] Add JSON as a Sphinx type for attributes (Daniel Vandersluis). +* [CHANGE] Remove polymorphic association and HABTM query support (when related to Thinking Sphinx) when ActiveRecord 3.2 is involved. +* [FIX] Don't try to delete guard files if they don't exist (@exAspArk). +* [FEATURE] minimal_group_by? can now be set in config/thinking_sphinx.yml to automatically apply to all index definitions. +* [FIX] Handle database settings reliably, now that ActiveRecord 4.2 uses strings all the time. +* [FIX] More consistent with escaping table names. +* [CHANGE] Remove default charset_type - no longer required for Sphinx 2.2. +* [FIX] Bug fix for association creation (with polymophic fields/attributes). +* [CHANGE] Removing sql_query_info setting, as it's no longer used by Sphinx (nor is it actually used by Thinking Sphinx). + 2015-01-21: 3.1.3 * [CHANGE] Log excerpt SphinxQL queries just like the search queries. * [CHANGE] Load Railtie if Rails::Railtie is defined, instead of just Rails (Andrew Cone). From 899eacc20c4b8d367e6806d6f31949065e8e1eac Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Mon, 1 Jun 2015 22:14:12 +1000 Subject: [PATCH 23/23] 3.1.4 --- HISTORY | 2 +- README.textile | 9 +++++---- thinking-sphinx.gemspec | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/HISTORY b/HISTORY index c696802fe..faa402998 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,4 @@ -Edge: +2015-06-01: 3.1.4 * [FIX] Kaminari expects prev_page to be available. * [CHANGE] Add a contributor code of conduct. * [FEATURE] Add JSON as a Sphinx type for attributes (Daniel Vandersluis). diff --git a/README.textile b/README.textile index 1d67b23d0..97c759b25 100644 --- a/README.textile +++ b/README.textile @@ -1,11 +1,12 @@ h1. Thinking Sphinx -Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v3.1.3. +Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v3.1.4. h2. Upgrading Please refer to the release notes for any changes you need to make when upgrading: +* "v3.1.4":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.4 * "v3.1.3":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.3 * "v3.1.2":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.2 * "v3.1.1":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.1 @@ -18,9 +19,9 @@ h2. Installation It's a gem, so install it like you would any other gem. You will also need to specify the mysql2 gem if you're using MRI, or jdbc-mysql if you're using JRuby: -
gem 'mysql2',          '~> 0.3.13', :platform => :ruby
-gem 'jdbc-mysql',      '~> 5.1.28', :platform => :jruby
-gem 'thinking-sphinx', '~> 3.1.3'
+
gem 'mysql2',          '~> 0.3.18', :platform => :ruby
+gem 'jdbc-mysql',      '~> 5.1.35', :platform => :jruby
+gem 'thinking-sphinx', '~> 3.1.4'
The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database. diff --git a/thinking-sphinx.gemspec b/thinking-sphinx.gemspec index e136099ee..890278281 100644 --- a/thinking-sphinx.gemspec +++ b/thinking-sphinx.gemspec @@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__) Gem::Specification.new do |s| s.name = 'thinking-sphinx' - s.version = '3.1.3' + s.version = '3.1.4' s.platform = Gem::Platform::RUBY s.authors = ["Pat Allan"] s.email = ["pat@freelancing-gods.com"]