Permalink
Browse files

Merge remote branch 'mtodd/add-toc-to-indexes'

Conflicts:
	ts/en/indexing.textile
  • Loading branch information...
2 parents c29da29 + 4e971ce commit e0fa17447fbb92e9859170e6d5c29f75493b92c9 @pat committed Apr 30, 2011
Showing with 14 additions and 5 deletions.
  1. +14 −5 ts/en/indexing.textile
View
@@ -5,6 +5,15 @@ title: Indexing
h2. Indexing your Models
+* "Basic Indexing":#basic
+* "Fields":#fields
+* "Attributes":#attributes
+* "Conditions and Groupings":#conditions
+* "Sanitizing SQL":#sql
+* "Processing your Index":#processing
+
+<h3 id="basic">Basic Indexing</h3>
+
Everything to set up the indexes for your models goes in the *define_index* method, within your model. Don't forget to place this block _below_ your associations, otherwise any references to them for fields and attributes will not work.
{% highlight ruby %}
@@ -23,7 +32,7 @@ class Article < ActiveRecord::Base
end
{% endhighlight %}
-h3. Fields
+<h3 id="fields">Fields</h3>
The @indexes@ method adds one (or many) fields, by referencing the model's column names. *You cannot reference model methods* - Sphinx talks directly to your database, and Ruby doesn't get loaded at this point.
@@ -70,7 +79,7 @@ indexes "LOWER(first_name)", :as => :first_name, :sortable => true
p. Again, in this situation, an explicit alias is required.
-h3. Attributes
+<h3 id="attributes">Attributes</h3>
The *has* method adds one (or many) attributes, and just like the *indexes* method, it requires references to the model's column names.
@@ -87,7 +96,7 @@ has :id, :as => :article_id
has tags(:id), :as => :tag_ids
{% endhighlight %}
-h3. Conditions and Groupings
+<h3 id="conditions">Conditions and Groupings</h3>
Because the index is translated to SQL, you may want to add some custom conditions or groupings manually - and for that, you'll want the @where@ and @group_by@ methods:
@@ -101,7 +110,7 @@ define_index do
end
{% endhighlight %}
-h3. SQL
+<h3 id="sql">Sanitizing SQL</h3>
As previously mentioned, your index definition results in SQL from the indexes, the attributes, conditions and groupings, etc. With this in mind, it may be useful to simplify your index.
@@ -117,7 +126,7 @@ end
This will produce the expected @WHERE published = 1@ for MySQL.
-h3. Processing your Index
+<h3 id="processing">Processing your Index</h3>
Once you've got your index set up just how you like it, you can run "the rake task":rake_tasks.html to get Sphinx to process the data.

0 comments on commit e0fa174

Please sign in to comment.