Skip to content

Commit

Permalink
Merge branch 'release/v3.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed May 13, 2016
2 parents 65f941f + 7482e69 commit 08e04ac
Show file tree
Hide file tree
Showing 70 changed files with 676 additions and 174 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- 2.1
- 2.2
- jruby-19mode
before_install:
- gem update --system
Expand All @@ -19,3 +19,8 @@ env:
- 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
sudo: false
addons:
postgresql: "9.4"
services:
- postgresql
8 changes: 4 additions & 4 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
appraise 'rails_3_2' do
gem 'rails', '~> 3.2.21'
gem 'rails', '~> 3.2.22.2'
end

appraise 'rails_4_0' do
gem 'rails', '~> 4.0.12'
gem 'rails', '~> 4.0.13'
end

appraise 'rails_4_1' do
gem 'rails', '~> 4.1.8'
gem 'rails', '~> 4.1.15'
end

appraise 'rails_4_2' do
gem 'rails', '~> 4.2.0'
gem 'rails', '~> 4.2.6'
end
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ gemspec
gem 'mysql2', '~> 0.3.12b4', :platform => :ruby
gem 'pg', '~> 0.16.0', :platform => :ruby

gem 'jdbc-mysql', '5.1.35', :platform => :jruby
gem 'activerecord-jdbcmysql-adapter', '~> 1.3.4', :platform => :jruby
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.4', :platform => :jruby

24 changes: 24 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
2016-05-13: 3.2.0
* [FIX] Ensure SQL table aliases are reliable for SQL-backed index queries.
* [FEATURE] Add JSON attribute support for real-time indices.
* [FEATURE] Add ability to disable *all* Sphinx-related callbacks via ThinkingSphinx::Callbacks.suspend! and ThinkingSphinx::Callbacks.resume!. Particularly useful for unit tests.
* [FEATURE] Add native OutOfBoundsError for search queries outside the pagination bounds.
* [CHANGE] Improved error messages for duplicate property names and missing columns.
* [FIX] Fixed mysql2 compatibility for memory references (Roman Usherenko).
* [FIX] Fixed JRuby compatibility with camelCase method names (Brandon Dewitt).
* [FEATURE] Support MySQL SSL options on a per-index level (@arrtchiu).
* [CHANGE] Don't populate search results when requesting just the count values (Andrew Roth).
* [CHANGE] Reset delta column before core indexing begins (reverting behaviour introduced in 3.1.0). See issue #958 for further discussion.
* [FEATURE] Allow for different indexing strategies (e.g. all at once, or one by one).
* [FIX] Fix stale id handling for multiple search contexts (Jonathan del Strother).
* [CHANGE] Use Sphinx's bulk insert ability (Chance Downs).
* [CHANGE] Reduce memory/object usage for model references (Jonathan del Strother).
* [CHANGE] Disable deletion callbacks when real-time indices are in place and all other real-time callbacks are disabled.
* [FIX] Handle quoting of namespaced tables (Roman Usherenko).
* [FIX] Make preload_indices thread-safe.
* [FIX] Improved handling of marshalled/demarshalled search results.
* [FEATURE] Allow rand_seed as a select option (Mattia Gheda).
* [FEATURE] Add primary_key option for index definitions (Nathaneal Gray).
* [FEATURE] Add ability to start searchd in the foreground (Andrey Novikov).
* [CHANGE] Only use ERB to parse the YAML file if ERB is loaded.

2015-06-01: 3.1.4
* [FIX] Kaminari expects prev_page to be available.
* [CHANGE] Add a contributor code of conduct.
Expand Down
9 changes: 5 additions & 4 deletions README.textile
Original file line number Diff line number Diff line change
@@ -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.4.
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.2.0.

h2. Upgrading

Please refer to the release notes for any changes you need to make when upgrading:

* "v3.2.0":https://github.com/pat/thinking-sphinx/releases/tag/v3.2.0
* "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
Expand All @@ -20,10 +21,10 @@ 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:

<pre><code>gem 'mysql2', '~> 0.3.18', :platform => :ruby
gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
gem 'thinking-sphinx', '~> 3.1.4'</code></pre>
gem 'jdbc-mysql', '= 5.1.35', :platform => :jruby
gem 'thinking-sphinx', '~> 3.2.0'</code></pre>

The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.
The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database. If you're using JRuby, there is "currently an issue with Sphinx and jdbc-mysql 5.1.36 or newer":http://sphinxsearch.com/forum/view.html?id=13939, so you'll need to stick to nothing more recent than 5.1.35.

You'll also need to install Sphinx - this is covered in "the extended documentation":http://pat.github.io/thinking-sphinx/installing_sphinx.html.

Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails_3_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ source "https://rubygems.org"

gem "mysql2", "~> 0.3.12b4", :platform => :ruby
gem "pg", "~> 0.16.0", :platform => :ruby
gem "jdbc-mysql", "5.1.35", :platform => :jruby
gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
gem "rails", "~> 3.2.21"
gem "rails", "~> 3.2.22.2"

gemspec :path => "../"
3 changes: 2 additions & 1 deletion gemfiles/rails_4_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ source "https://rubygems.org"

gem "mysql2", "~> 0.3.12b4", :platform => :ruby
gem "pg", "~> 0.16.0", :platform => :ruby
gem "jdbc-mysql", "5.1.35", :platform => :jruby
gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
gem "rails", "~> 4.0.12"
gem "rails", "~> 4.0.13"

gemspec :path => "../"
3 changes: 2 additions & 1 deletion gemfiles/rails_4_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ source "https://rubygems.org"

gem "mysql2", "~> 0.3.12b4", :platform => :ruby
gem "pg", "~> 0.16.0", :platform => :ruby
gem "jdbc-mysql", "5.1.35", :platform => :jruby
gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
gem "rails", "~> 4.1.8"
gem "rails", "~> 4.1.15"

gemspec :path => "../"
3 changes: 2 additions & 1 deletion gemfiles/rails_4_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ source "https://rubygems.org"

gem "mysql2", "~> 0.3.12b4", :platform => :ruby
gem "pg", "~> 0.16.0", :platform => :ruby
gem "jdbc-mysql", "5.1.35", :platform => :jruby
gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
gem "rails", "~> 4.2.0"
gem "rails", "~> 4.2.6"

gemspec :path => "../"
5 changes: 4 additions & 1 deletion lib/thinking_sphinx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

module ThinkingSphinx
def self.count(query = '', options = {})
search(query, options).total_entries
search_for_ids(query, options).total_entries
end

def self.facets(query = '', options = {})
Expand All @@ -39,6 +39,7 @@ def self.before_index_hooks
@before_index_hooks = []

module Subscribers; end
module IndexingStrategies; end
end

# Core
Expand All @@ -57,6 +58,8 @@ module Subscribers; end
require 'thinking_sphinx/frameworks'
require 'thinking_sphinx/guard'
require 'thinking_sphinx/index'
require 'thinking_sphinx/indexing_strategies/all_at_once'
require 'thinking_sphinx/indexing_strategies/one_at_a_time'
require 'thinking_sphinx/index_set'
require 'thinking_sphinx/masks'
require 'thinking_sphinx/middlewares'
Expand Down
1 change: 1 addition & 0 deletions lib/thinking_sphinx/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Callbacks; end
require 'thinking_sphinx/active_record/property_query'
require 'thinking_sphinx/active_record/property_sql_presenter'
require 'thinking_sphinx/active_record/simple_many_query'
require 'thinking_sphinx/active_record/source_joins'
require 'thinking_sphinx/active_record/sql_builder'
require 'thinking_sphinx/active_record/sql_source'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def indices
@indices ||= begin
configuration.preload_indices
configuration.indices_for_references(
*@association.klass.name.underscore.to_sym
*ThinkingSphinx::IndexSet.reference_name(@association.klass)
).reject &:distributed?
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/active_record/attribute/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def single_column_reference?

def type_from_database
raise ThinkingSphinx::MissingColumnError,
"column #{column_name} does not exist" if database_column.nil?
"Cannot determine the database type of column #{column_name}, as it does not exist" if database_column.nil?

return :bigint if big_integer?

Expand Down
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/active_record/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def search(query = nil, options = {})
end

def search_count(query = nil, options = {})
search(query, options).total_entries
search_for_ids(query, options).total_entries
end

def search_for_ids(query = nil, options = {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks <
callbacks :after_destroy

def after_destroy
return if instance.new_record?
return if ThinkingSphinx::Callbacks.suspended? || instance.new_record?

indices.each { |index|
ThinkingSphinx::Deletion.perform index, instance.id
Expand Down
10 changes: 7 additions & 3 deletions lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
callbacks :after_commit, :before_save

def after_commit
return unless delta_indices? && processors.any? { |processor|
return unless !suspended? && delta_indices? && processors.any? { |processor|
processor.toggled?(instance)
} && !ThinkingSphinx::Deltas.suspended?
}

delta_indices.each do |index|
index.delta_processor.index index
Expand All @@ -18,7 +18,7 @@ def after_commit
end

def before_save
return unless delta_indices?
return unless !ThinkingSphinx::Callbacks.suspended? && delta_indices?

processors.each { |processor| processor.toggle instance }
end
Expand Down Expand Up @@ -48,4 +48,8 @@ def indices
def processors
delta_indices.collect &:delta_processor
end

def suspended?
ThinkingSphinx::Callbacks.suspended? || ThinkingSphinx::Deltas.suspended?
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks <
callbacks :after_update

def after_update
return unless updates_enabled?
return unless !ThinkingSphinx::Callbacks.suspended? && updates_enabled?

indices.each do |index|
update index unless index.distributed?
Expand Down Expand Up @@ -35,7 +35,7 @@ def indices
end

def reference
instance.class.name.underscore.to_sym
ThinkingSphinx::IndexSet.reference_name(instance.class)
end

def update(index)
Expand Down
6 changes: 5 additions & 1 deletion lib/thinking_sphinx/active_record/column_sql_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def with_table
return __name if string?
return nil unless exists?

quoted_table = escape_table? ? adapter.quote(table) : table
quoted_table = escape_table? ? escape_table(table) : table

"#{quoted_table}.#{adapter.quote __name}"
end
Expand All @@ -24,6 +24,10 @@ def with_table

delegate :__stack, :__name, :string?, :to => :column

def escape_table(table_name)
table_name.split('.').map { |t| adapter.quote(t) }.join('.')
end

def escape_table?
table[/[`"]/].nil?
end
Expand Down
8 changes: 4 additions & 4 deletions lib/thinking_sphinx/active_record/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def facets
@facets ||= sources.collect(&:facets).flatten
end

def fields
sources.collect(&:fields).flatten
end

def sources
interpret_definition!
super
Expand All @@ -44,10 +48,6 @@ def adapter
adapter_for(model)
end

def fields
sources.collect(&:fields).flatten
end

def interpreter
ThinkingSphinx::ActiveRecord::Interpreter
end
Expand Down
55 changes: 55 additions & 0 deletions lib/thinking_sphinx/active_record/source_joins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class ThinkingSphinx::ActiveRecord::SourceJoins
def self.call(model, source)
new(model, source).call
end

def initialize(model, source)
@model, @source = model, source
end

def call
append_specified_associations
append_property_associations

joins
end

private

attr_reader :model, :source

def append_property_associations
source.properties.collect(&:columns).each do |columns|
columns.each { |column| append_column_associations column }
end
end

def append_column_associations(column)
return if column.__stack.empty?

joins.add_join_to column.__stack if column_exists?(column)
end

def append_specified_associations
source.associations.reject(&:string?).each do |association|
joins.add_join_to association.stack
end
end

def column_exists?(column)
Joiner::Path.new(model, column.__stack).model
true
rescue Joiner::AssociationNotFound
false
end

def joins
@joins ||= begin
joins = Joiner::Joins.new model
if joins.respond_to?(:join_association_class)
joins.join_association_class = ThinkingSphinx::ActiveRecord::JoinAssociation
end
joins
end
end
end
21 changes: 3 additions & 18 deletions lib/thinking_sphinx/active_record/sql_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ def sql_query_pre
query.to_query
end

def sql_query_post_index
return [] unless delta_processor && !source.delta?

[delta_processor.reset_query]
end

private

delegate :adapter, :model, :delta_processor, :to => :source
Expand All @@ -49,18 +43,9 @@ def relation
end

def associations
@associations ||= begin
joins = Joiner::Joins.new model
if joins.respond_to?(:join_association_class)
joins.join_association_class = ThinkingSphinx::ActiveRecord::JoinAssociation
end

source.associations.reject(&:string?).each do |association|
joins.add_join_to association.stack
end

joins
end
@associations ||= ThinkingSphinx::ActiveRecord::SourceJoins.call(
model, source
)
end

def quote_column(column)
Expand Down
Loading

0 comments on commit 08e04ac

Please sign in to comment.