<commit_before>h1. Thinking Sphinx

Welcome to Thinking Sphinx version 3 - a complete rewrite from past versions, built for Rails 3.1 or newer only.

h2. Installation

It's a gem, so install it like you would any other gem. You will also need to specify the Mysql2 gem as well (this is not an inbuilt dependency because JRuby, when supported, will need something different):

<pre><code>gem 'mysql2',          '0.3.12b4'
gem 'thinking-sphinx', '3.0.0'</code></pre>

The mysql2 gem is required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.

As for Sphinx itself, you need to make sure it's compiled with MySQL support, even if you're using PostgreSQL as your database - which is normally the default, but Homebrew can be too smart sometimes. If that's your compiling tool of choice, make sure you install with the @--mysql@ flag:

<pre><code>brew install sphinx --mysql</code></pre>

h2. Usage

Indexes are no longer defined in models - they now live in `app/indices` (which you will need to create yourself). Each index should get its own file, and look something like this:

<pre><code># app/indices/article_index.rb
ThinkingSphinx::Index.define :article, :with => :active_record do
  indexes title, content
  indexes user.name, :as => :user
  indexes user.articles.title, :as => :related_titles

  has published
end</code></pre>

You'll notice the first argument is the model name downcased and as a symbol, and we are specifying the processor - @:active_record@. Everything inside the block is just like previous versions of Thinking Sphinx. Same goes for @config/thinking_sphinx.yml@ (formerly @config/sphinx.yml@).

When you're defining indices for namespaced models, use a lowercase string with /'s for namespacing as the model reference:

<pre><code># For a model named Blog::Article:
ThinkingSphinx::Index.define 'blog/article', :with => :active_record</code></pre>

Other changes:
* SphinxQL is now used instead of the old socket connections (hence the dependency on the @mysql2@ gem).
* You'll need to include @ThinkingSphinx::Scopes@ into your models if you want to use Sphinx scopes. Default scopes can be set as follows:

<pre><code>class Person < ActiveRecord::Base
  include ThinkingSphinx::Scopes

  sphinx_scope(:date_order) { {:order => :created_at} }<commit_msg>Noting a few missing setting changes. Closes #458.<commit_after>h1. Thinking Sphinx

Welcome to Thinking Sphinx version 3 - a complete rewrite from past versions, built for Rails 3.1 or newer only.

h2. Installation

It's a gem, so install it like you would any other gem. You will also need to specify the Mysql2 gem as well (this is not an inbuilt dependency because JRuby, when supported, will need something different):

<pre><code>gem 'mysql2',          '0.3.12b4'
gem 'thinking-sphinx', '3.0.0'</code></pre>

The mysql2 gem is required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.

As for Sphinx itself, you need to make sure it's compiled with MySQL support, even if you're using PostgreSQL as your database - which is normally the default, but Homebrew can be too smart sometimes. If that's your compiling tool of choice, make sure you install with the @--mysql@ flag:

<pre><code>brew install sphinx --mysql</code></pre>

h2. Usage

Indexes are no longer defined in models - they now live in `app/indices` (which you will need to create yourself). Each index should get its own file, and look something like this:

<pre><code># app/indices/article_index.rb
ThinkingSphinx::Index.define :article, :with => :active_record do
  indexes title, content
  indexes user.name, :as => :user
  indexes user.articles.title, :as => :related_titles

  has published
end</code></pre>

You'll notice the first argument is the model name downcased and as a symbol, and we are specifying the processor - @:active_record@. Everything inside the block is just like previous versions of Thinking Sphinx. Same goes for most settings in @config/thinking_sphinx.yml@ (formerly @config/sphinx.yml@) unless noted below.

When you're defining indices for namespaced models, use a lowercase string with /'s for namespacing as the model reference:

<pre><code># For a model named Blog::Article:
ThinkingSphinx::Index.define 'blog/article', :with => :active_record</code></pre>

Other changes:
* SphinxQL is now used instead of the old socket connections (hence the dependency on the @mysql2@ gem).
* Specifying a different port for Sphinx to use (in @config/thinking_sphinx.yml@) should be done with the mysql41 setting, not the port setting.
* The searchd_log and searchd_query_log settings are now log and query_log (matching their Sphinx names).
* You'll need to include @ThinkingSphinx::Scopes@ into your models if you want to use Sphinx scopes. Default scopes can be set as follows:

<pre><code>class Person < ActiveRecord::Base
  include ThinkingSphinx::Scopes

  sphinx_scope(:date_order) { {:order => :created_at} }
{'fraction_non_alphanumeric': 0.0841009211053264, 'fraction_numerical': 0.008209851822186623, 'mean_word_length': 4.656851642129105, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2917395', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1415, 'n_words': 672}