[LRUG] [Off Topic] Sphinx Filter

Andrew Stewart boss at airbladesoftware.com
Thu Apr 24 09:00:10 PDT 2008


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







More information about the Chat mailing list