[LRUG] [Off Topic] Sphinx Filter
Andrew Stewart
boss at airbladesoftware.com
Fri Apr 25 03:37:48 PDT 2008
On 25 Apr 2008, at 01:09, Pat Allan wrote:
> That aside, you'll want to set up an attribute (not a field) for the
> published column - as attributes are ints, bools, floats, datetimes
> and strings-converted-to-ordinal-ints (last is only useful for
> sorting, not filtering). Then, as Steve's pointed out, you can filter
> on it.
Aha! I hadn't appreciated the difference between attributes and
fields. I read Sphinx's docs and Thinking Sphinx's docs (excellent,
by the way) and now I understand.
> Not sure if Sphincter supports attributes, but both Ultrasphinx and
> Thinking Sphinx (disclosure: my own plugin) do.
It turns out that Sphincter handles attributes automatically; so
automatically that neither the documentation nor the API mentions
them or explain their significance. I guess that's both good and bad
depending on your point of view.
Anyway, I make article model searchable like this:
class Article < ActiveRecord::Base
add_index :fields => %w( title body published )
end
-- and Sphincter takes care of using the published column as an
attribute to filter on...once you've rebuilt the Sphinx configuration
file. Not doing so was the cause of my lower-level problem. Now the
command line search works fine:
$ search -c sphinx/development/sphinx.conf -i articles -f published 1
portim
My search code looks like this:
Article.search 'foo', :conditions => {:published => 1}, :page =>
blah, :per_page => blah
As you can(not) see, no explicit attributes in sight.
Anyway, somewhere along the line I realised Sphincter doesn't support
delta indexing, and so when I make an article unpublished, I need to
rebuild the index. My tests were going awry because I wasn't
reindexing every time I toggled an article's published column. I am
now, and everything works as expected.
> They also have the
> advantage of working with the latest version of Sphinx.
Aah. I also notice that Sphincter causes Sphinx to generate lots of
deprecation warnings like "key 'sql_group_column' is deprecated ...;
use 'sql_attr_uint' instead."
Having checked out Ultrasphinx and Thinking Sphinx, I'm a whisker
away from replacing Sphincter with one of them. I'll certainly do it
if I need a capability that Sphincter doesn't offer. I'd probably go
with Thinking Sphinx because the documentation is clearer and I think
I prefer its API.
So thanks Pat and Steve for your help.
Cheers,
Andy
-------
AirBlade Software
http://airbladesoftware.com
More information about the Chat
mailing list