views:

407

answers:

1

Hi,

I've recently installed thinking-sphinx on my ruby on rails app. As first sight, everything works great, I can search words and it will find them. Now, when I try to add some filters(such as, for example, provinces, categories, etc) using:

MyModel.search 'hello' :conditions => 'category_id=1' for example, it will throw me the following exception:

searchd error (status: 1): invalid or truncated request

I've been reading some docs on the thinking-sphinx plugin, and I guess I have to do something else than this syntax.

To summarize: until the moment, I just installed the windows service, then I defined a index in one model, and then i tried to search. Again, I succeeded while searching without conditions, but failed while searching with.

Any help will be appreciated.

Thanks, Brian

+2  A: 

Assuming your model has category_id:

MyModel.search 'hello', :with => {:category_id => 1}

:conditions is for full text searching specific attributes, :with is for filtering search results.

More info here: http://freelancing-gods.com/posts/a_concise_guide_to_using_thinking_sphinx

cwninja
Well. Actually I'm working on the Announcement model, and I've got the following: acts_as_taggable_on :tags,:categoryIf I wanted to add a condition in the search for tags, what should I include in my index at Announcement?
Brian Roisentul
Also, you must know that I don't have any Tag model. I just simply have the db tables and the acts_as_taggable_on plugin, which I use at the Announcement model as I said on my previous comment.
Brian Roisentul
It's a none trivial problem, try has "concat(select tags.value where my_model_id = my_models.id)" or similar. You can pass arbitrary SQL, my advice would be to look at the SQL generated in the sphinx.conf file and reverse engineer it.
cwninja