[LRUG] [Off Topic] Sphinx Filter

Pat Allan pat at freelancing-gods.com
Thu Apr 24 17:09:53 PDT 2008


Hi Andy

I'm not sure on Sphincter's syntax, so I'm no help there (although  
from a glance at the docs, it looks like you're doing the right thing  
with the hash - I very much doubt a string will work (because of how  
Sphinx queries are sent to the daemon).

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.

Not sure if Sphincter supports attributes, but both Ultrasphinx and  
Thinking Sphinx (disclosure: my own plugin) do. They also have the  
advantage of working with the latest version of Sphinx.

Cheers

-- 
Pat
e: pat at freelancing-gods.com    || m: 0413 273 337
w: http://freelancing-gods.com || p: 03 9386 0928
discworld: http://ausdwcon.org || skype: patallan

On 25/04/2008, at 2:00 AM, Andrew Stewart wrote:

> Hello El Rug,
>
> I'm using a Ruby library that uses Sphinx to search my database, and
> can't seem to get conditions working in my application's search
> code.  To try to isolate the problem, I stopped debugging from the
> application down and started working from the database up.  However I
> got stuck that way too!
>
> If anyone can help with either stuckage, that would be great.
>
>
> * Lower-level Problem
>
> The articles table I'm searching has a boolean published column.
> (Being MySQL, this is a tinyint(1).)  I want to search the published
> articles.  I have configured Sphinx to index the published and title
> columns.
>
> MySQL:
> mysql> select * from articles where published = 1 and title like '%
> portim%';
> => correctly returns the published articles with portim in the title.
>
> Sphinx via the command line:
> $ search -c sphinx/development/sphinx.conf -i articles portim
> => correctly returns the articles with portim in the title
>
> But how to get Sphinx to stick to published articles?  None of these
> works:
>
> search -c sphinx/development/sphinx.conf -i articles -f published 1
> portim
> search -c sphinx/development/sphinx.conf -i articles -f published [1]
> portim
> search -c sphinx/development/sphinx.conf -i articles -f 'published' 1
> portim
> search -c sphinx/development/sphinx.conf -i articles -f 'published 1'
> portim
> search -c sphinx/development/sphinx.conf -i articles -f 'published'
> '1' portim
>
>
> * Higher-level Problem
>
> My app uses Sphincter to perform the searches.  You can pass a hash
> to the search method, with a key for any conditions.
>
> If I specify the conditions like this:
>
>   :conditions => {:published => 1}
>
> -- then it fails to retrieve published articles.
>
> If I specify the conditions like this:
>
>   :conditions => ['published = 1']
>
> -- then it fails to ignore unpublished articles.
>
> Why?!
>
>
> Thanks and regards,
> Andy
>
> -------
> AirBlade Software
> http://airbladesoftware.com
>
>
>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org



More information about the Chat mailing list