Skip to content

Commit

Permalink
Merge branch 'release/v3.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Jan 21, 2015
2 parents cad9d58 + 3a1355b commit 6e7e0fd
Show file tree
Hide file tree
Showing 52 changed files with 624 additions and 446 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ env:
gemfile:
- gemfiles/rails_3_2.gemfile
- gemfiles/rails_4_0.gemfile
- gemfiles/rails_4_1.gemfile
- gemfiles/rails_4_2.gemfile
10 changes: 7 additions & 3 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
appraise 'rails_3_2' do
gem 'rails', '~> 3.2.0'
gem 'rails', '~> 3.2.21'
end

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

appraise 'rails_4_1' do
gem 'rails', '~> 4.1.0.beta1'
gem 'rails', '~> 4.1.8'
end

appraise 'rails_4_2' do
gem 'rails', '~> 4.2.0'
end
12 changes: 12 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
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).
* [CHANGE] Convert raw Sphinx results to an array when querying (Bryan Ricker).
* [FIX] Generate de-polymorphised associations properly for Rails 4.2
* [FIX] Use reflect_on_association instead of reflections, to stick to the public ActiveRecord::Base API.
* [FIX] Don't load ActiveRecord early - fixes a warning in Rails 4.2.
* [FEATURE] Allow for custom offset references with the :offset_as option - thus one model across many schemas with Apartment can be treated differently.
* [FEATURE] Allow for custom IndexSet classes.
* [FIX] Don't double-up on STI filtering, already handled by Rails.
* [CHANGE] Add bigint support for real-time indices, and use bigints for the sphinx_internal_id attribute (mapped to model primary keys) (Chance Downs).

2014-11-04: 3.1.2
* [CHANGE] regenerate task now only deletes index files for real-time indices.
* [CHANGE] Raise an exception when a populated search query is modified (as it can't be requeried).
Expand Down
8 changes: 5 additions & 3 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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.1.
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.

h2. Upgrading

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

* "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
* "v3.1.0":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.0
* "v3.0.6":https://github.com/pat/thinking-sphinx/releases/tag/v3.0.6
Expand All @@ -18,7 +20,7 @@ It's a gem, so install it like you would any other gem. You will also need to sp

<pre><code>gem 'mysql2', '~> 0.3.13', :platform => :ruby
gem 'jdbc-mysql', '~> 5.1.28', :platform => :jruby
gem 'thinking-sphinx', '~> 3.1.1'</code></pre>
gem 'thinking-sphinx', '~> 3.1.3'</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.

Expand Down Expand Up @@ -75,4 +77,4 @@ You can then run the unit tests with @rake spec:unit@, the acceptance tests with

h2. Licence

Copyright (c) 2007-2014, Thinking Sphinx is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to "all who have contributed patches":https://github.com/pat/thinking-sphinx/contributors.
Copyright (c) 2007-2015, Thinking Sphinx is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to "all who have contributed patches":https://github.com/pat/thinking-sphinx/contributors.
2 changes: 1 addition & 1 deletion gemfiles/rails_3_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ 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.0"
gem "rails", "~> 3.2.21"

gemspec :path=>"../"
2 changes: 1 addition & 1 deletion gemfiles/rails_4_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ 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.2"
gem "rails", "~> 4.0.12"

gemspec :path=>"../"
2 changes: 1 addition & 1 deletion gemfiles/rails_4_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ 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.0.beta1"
gem "rails", "~> 4.1.8"

gemspec :path=>"../"
11 changes: 11 additions & 0 deletions gemfiles/rails_4_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was generated by Appraisal

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 "rails", "~> 4.2.0"

gemspec :path=>"../"
2 changes: 1 addition & 1 deletion lib/thinking_sphinx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ module Subscribers; end
require 'thinking_sphinx/logger'
require 'thinking_sphinx/real_time'

require 'thinking_sphinx/railtie' if defined?(Rails)
require 'thinking_sphinx/railtie' if defined?(Rails::Railtie)
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Callbacks; end
require 'thinking_sphinx/active_record/column_sql_presenter'
require 'thinking_sphinx/active_record/database_adapters'
require 'thinking_sphinx/active_record/field'
require 'thinking_sphinx/active_record/filtered_reflection'
require 'thinking_sphinx/active_record/filter_reflection'
require 'thinking_sphinx/active_record/index'
require 'thinking_sphinx/active_record/interpreter'
require 'thinking_sphinx/active_record/join_association'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def after_destroy
private

def indices
ThinkingSphinx::IndexSet.new([instance.class], []).to_a
ThinkingSphinx::Configuration.instance.index_set_class.new(
:classes => [instance.class]
).to_a
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def delta_indices?
end

def indices
@indices ||= ThinkingSphinx::IndexSet.new [instance.class], []
@indices ||= config.index_set_class.new :classes => [instance.class]
end

def processors
Expand Down
75 changes: 75 additions & 0 deletions lib/thinking_sphinx/active_record/filter_reflection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class ThinkingSphinx::ActiveRecord::FilterReflection
attr_reader :reflection, :class_name

delegate :foreign_type, :active_record, :to => :reflection

def self.call(reflection, name, class_name)
filter = new(reflection, class_name)
klass = reflection.class

if defined?(ActiveRecord::Reflection::MacroReflection)
klass.new name, filter.scope, filter.options, reflection.active_record
elsif reflection.respond_to?(:scope)
klass.new reflection.macro, name, filter.scope, filter.options,
reflection.active_record
else
klass.new reflection.macro, name, filter.options,
reflection.active_record
end
end

def initialize(reflection, class_name)
@reflection, @class_name = reflection, class_name
@options = reflection.options.clone
end

def options
@options.delete :polymorphic
@options[:class_name] = class_name
@options[:foreign_key] ||= "#{reflection.name}_id"
@options[:foreign_type] = reflection.foreign_type

if reflection.respond_to?(:scope)
@options[:sphinx_internal_filtered] = true
return @options
end

case @options[:conditions]
when nil
@options[:conditions] = condition
when Array
@options[:conditions] << condition
when Hash
@options[:conditions].merge!(reflection.foreign_type => @options[:class_name])
else
@options[:conditions] << " AND #{condition}"
end

@options
end

def scope
if ::Joiner::Joins.instance_methods.include?(:join_association_class)
return nil
end

lambda { |association|
reflection = association.reflection
klass = reflection.class_name.constantize
where(
association.parent.aliased_table_name.to_sym =>
{reflection.foreign_type => klass.base_class.name}
)
}
end

private

def condition
"::ts_join_alias::.#{quoted_foreign_type} = '#{class_name}'"
end

def quoted_foreign_type
active_record.connection.quote_column_name foreign_type
end
end
75 changes: 0 additions & 75 deletions lib/thinking_sphinx/active_record/filtered_reflection.rb

This file was deleted.

8 changes: 4 additions & 4 deletions lib/thinking_sphinx/active_record/polymorpher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def morph!

def append_reflections
mappings.each do |class_name, name|
next if klass.reflections[name]
next if klass.reflect_on_association(name)

reflection = clone_with name, class_name
if ActiveRecord::Reflection.respond_to?(:add_reflection)
Expand All @@ -26,7 +26,7 @@ def append_reflections
end

def clone_with(name, class_name)
ThinkingSphinx::ActiveRecord::FilteredReflection.clone_with_filter(
ThinkingSphinx::ActiveRecord::FilterReflection.call(
reflection, name, class_name
)
end
Expand All @@ -51,12 +51,12 @@ def morph_properties
end

def reflection
@reflection ||= klass.reflections[column.__name]
@reflection ||= klass.reflect_on_association column.__name
end

def klass
@klass ||= column.__stack.inject(source.model) { |parent, key|
parent.reflections[key].klass
parent.reflect_on_association(key).klass
}
end
end
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/active_record/property_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def reflections
base = source.model

column.__stack.collect { |key|
reflection = base.reflections[key]
reflection = base.reflect_on_association key
base = reflection.klass

extend_reflection reflection
Expand Down
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/active_record/simple_many_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def to_s
private

def reflection
@reflection ||= source.model.reflections[column.__stack.first]
@reflection ||= source.model.reflect_on_association column.__stack.first
end

def quoted_foreign_key
Expand Down
4 changes: 0 additions & 4 deletions lib/thinking_sphinx/active_record/sql_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ def reversed_document_id
"($id - #{source.offset}) / #{config.indices.count}"
end

def inheritance_column_condition
"#{quoted_inheritance_column} = '#{model_name}'"
end

def range_condition
condition = []
condition << "#{quoted_primary_key} BETWEEN $start AND $end" unless source.disable_range?
Expand Down
1 change: 0 additions & 1 deletion lib/thinking_sphinx/active_record/sql_builder/statement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def select_clause

def where_clause(for_range = false)
builder = SQLBuilder::ClauseBuilder.new(nil)
builder.add_clause inheritance_column_condition unless model.descends_from_active_record?
builder.add_clause delta_processor.clause(source.delta?) if delta_processor
builder.add_clause range_condition unless for_range
builder.separated(' AND ')
Expand Down
9 changes: 6 additions & 3 deletions lib/thinking_sphinx/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ThinkingSphinx::Configuration < Riddle::Configuration
attr_accessor :configuration_file, :indices_location, :version
attr_reader :index_paths
attr_writer :controller
attr_writer :controller, :index_set_class

delegate :environment, :to => :framework

Expand Down Expand Up @@ -56,9 +56,12 @@ def engine_indice_paths
end
end

def index_set_class
@index_set_class ||= ThinkingSphinx::IndexSet
end

def indices_for_references(*references)
preload_indices
indices.select { |index| references.include?(index.reference) }
index_set_class.new(:references => references).to_a
end

def next_offset(reference)
Expand Down
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/core/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(reference, options = {})
@docinfo = :extern
@charset_type = 'utf-8'
@options = options
@offset = config.next_offset(reference)
@offset = config.next_offset(options[:offset_as] || reference)
@type = 'plain'

super "#{options[:name] || reference.to_s.gsub('/', '_')}_#{name_suffix}"
Expand Down
Loading

0 comments on commit 6e7e0fd

Please sign in to comment.