Skip to content

Commit

Permalink
Merge branch 'release/v3.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Jun 1, 2015
2 parents 6e7e0fd + 899eacc commit 65f941f
Show file tree
Hide file tree
Showing 26 changed files with 163 additions and 101 deletions.
16 changes: 7 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ 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
- 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
gemfile:
- gemfiles/rails_3_2.gemfile
- gemfiles/rails_4_0.gemfile
- gemfiles/rails_4_1.gemfile
- gemfiles/rails_4_2.gemfile
- 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
13 changes: 13 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
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).
* [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).
Expand Down
13 changes: 9 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.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
Expand All @@ -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:

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

The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.

Expand All @@ -44,6 +45,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
Expand All @@ -58,6 +61,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.
Expand Down
10 changes: 5 additions & 5 deletions gemfiles/rails_3_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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=>"../"
gemspec :path => "../"
10 changes: 5 additions & 5 deletions gemfiles/rails_4_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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=>"../"
gemspec :path => "../"
10 changes: 5 additions & 5 deletions gemfiles/rails_4_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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=>"../"
gemspec :path => "../"
10 changes: 5 additions & 5 deletions gemfiles/rails_4_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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=>"../"
gemspec :path => "../"
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 15 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,9 @@ def with_table
return __name if string?
return nil unless exists?

"#{associations.alias_for(__stack)}.#{adapter.quote __name}"
quoted_table = escape_table? ? adapter.quote(table) : table

"#{quoted_table}.#{adapter.quote __name}"
end

private
Expand All @@ -22,6 +24,10 @@ def with_table

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

def escape_table?
table[/[`"]/].nil?
end

def exists?
path.model.column_names.include?(column.__name.to_s)
rescue Joiner::AssociationNotFound
Expand All @@ -31,4 +37,12 @@ def exists?
def path
Joiner::Path.new model, column.__stack
end

def table
associations.alias_for __stack
end

def version
ActiveRecord::VERSION
end
end
3 changes: 2 additions & 1 deletion lib/thinking_sphinx/active_record/filter_reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/thinking_sphinx/active_record/interpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions lib/thinking_sphinx/active_record/sql_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
18 changes: 7 additions & 11 deletions lib/thinking_sphinx/active_record/sql_builder/statement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -140,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
1 change: 0 additions & 1 deletion lib/thinking_sphinx/active_record/sql_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/thinking_sphinx/core/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/guard/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def path
end

def unlock
FileUtils.rm path
FileUtils.rm(path) if locked?
end
end
2 changes: 2 additions & 0 deletions lib/thinking_sphinx/masks/pagination_mask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/big_integers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/excerpts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

search.first.excerpts.title.
should == 'Война и <span class="match">миръ</span>'
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'
Expand Down
16 changes: 8 additions & 8 deletions spec/acceptance/specifying_sql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
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./)
end
query.should match(/.articles.\..title., .books.\..title./)
end if ActiveRecord::VERSION::MAJOR > 3

it "concatenates references that have column" do
index = ThinkingSphinx::ActiveRecord::Index.new(:event)
Expand All @@ -139,8 +139,8 @@
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./)
end
query.should match(/.articles.\..title./)
end if ActiveRecord::VERSION::MAJOR > 3

it "respects deeper associations through polymorphic joins" do
index = ThinkingSphinx::ActiveRecord::Index.new(:event)
Expand All @@ -153,9 +153,9 @@
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
end if ActiveRecord::VERSION::MAJOR > 3

describe 'separate queries for MVAs' do
let(:index) { ThinkingSphinx::ActiveRecord::Index.new(:article) }
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 65f941f

Please sign in to comment.