ThinkingSphinx not accepting conditions
-
03-07-2019 - |
Question
I'm having trouble getting ThinkingSphinx to recognize my conditions.
My Discussion model includes the following code:
define_index do
indexes [subject, body], :as => :text
indexes replies.body, :as => :reply_text
set_property :delta => true
end
And as expected this search
Discussion.search "handy"
returns any discussion with the word "handy" in its subject, body, or the body of one of its replies.
Now I'm implementing a "deleting posts" feature, and I want to show only discussions where the field called :disabled == false.
Unfortunately, this search:
Discussion.search "handy", :conditions => { :disabled => false }
always returns an empty array, no matter what.
Why?
Solution
You'll need to have an attribute disabled
defined in your define_index
block:
define_index do
indexes [subject, body], :as => :text
indexes replies.body, :as => :reply_text
has disabled
set_property :delta => true
end
Once you've done this, stop Sphinx, re-index, and restart, and hopefully it should work.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow