pat/thinking-sphinx — pull request #636 by bricker (2013-10-18 05:32:34+00:00)
Title: Ensure all classes being searched on have an index defined

This one has code attached!

When attempting to perform a search on a class without an index, this happens:

```
> Article.search.to_a
NoMethodError: undefined method `options' for nil:NilClass
from .../thinking-sphinx/lib/thinking_sphinx/middlewares/sphinxql.rb:130:in `index_options'
```

That error isn't very helpful. With this patch, a more useful error is raised:

```
> Article.search.to_a
ThinkingSphinx::MissingIndexError: Can't search on a class which doesn't have an index definition. (Article)
from .../thinking-sphinx/lib/thinking_sphinx/search.rb:104:in `enforce_all_classes_have_indices'
```

This doesn't change the behavior, since an error was being raised anyways... just more helpful now.

This code also adds back in two methods from thinking-sphinx v2:

* `ActiveRecord::Base.has_sphinx_indices?` (formerly `has_sphinx_indexes?`) -
Checks if the class has any indices defined. This method is used when
enforcing the presence of an index before population.

* `ActiveRecord::Base.sphinx_index_names` - An array of index names for
this model, eg `["article_core"]`. This method doesn't actually get used
anywhere else, I just find it useful and feel it goes hand-in-hand with
`has_sphinx_indices?`.

Finally, a small optimization: the code changes `ThinkingSphinx::IndexSet.new` to only
require the first argument. The second argument, `index_names`, [gets checked for falsey
anyways](https://github.com/pat/thinking-sphinx/blob/master/lib/thinking_sphinx/index_set.rb#L39), so may as well not require it.