Sphinx has no concept of relationships between models/indices. So, with the 
attribute you'd had defined earlier, each project in Sphinx would have an array 
of integers (1 representing trues, 0 representing falses). There's no 
connection between each of those values and the courses they originally came 
from.

With that standard attribute (no SQL snippet), it should still work, but the 
filter is saying "give me all projects where there is the value 1 (true) in the 
is_visible attribute." This will return projects which have at least one 
visible course, but they may have invisible courses as well.

Although, now that I'm thinking about it, this should work:

  has courses.is_visible, as: :is_visible

And then searching, use without instead of with:

  Project.search 'foo', without: {is_visible: false}

So we've switched it to say "give me all projects where there is no value 0 
(false) in the is_visible attribute."

Hope this helps!

-- 
Pat

On 18 Jun 2014, at 9:55 am, Daniel Gottschalck <[email protected]> wrote:

> Hey Pat
> 
> Thanks.
> 
> It looks like a rather difficult task to filter on a boolean in a relational 
> model?
> 
> I will try it out when I get home and give a response, thanks.
> 
> Regards
> 
> Den tirsdag den 17. juni 2014 20.56.23 UTC+2 skrev Daniel Gottschalck:
> Hey
> 
> 
> In the website, there is "projects", and "projects" can have "courses".
> 
> 
> In my project index file, how would I filter on "courses" which "is_visible" 
> true?
> 
> Im confused on whether to use "has" or "indexes" for a relation model boolean 
> value.
> 
>  
> ThinkingSphinx::Index.define 'refinery/wayfinders/project', :with => 
> :active_record do
>       indexes :name, sortable: true
>       indexes :city
>       indexes :description
>       indexes courses.name, as: :course_name
> 
>       indexes courses.is_visible, as: :is_visible <------------------------ 
> This one?
> 
>       set_property :group_concat_max_len => 8192
>       has zip, external_id
>  
>       has courses.is_visible, as: :is_visible, type: :boolean 
> <------------------- Or this one?
> end
> 
> And how would I then filter it in my search_controller? So I only get courses 
> which are visible?
> 
> @project_search = Refinery::Wayfinders::Project.search(params[:search], :with 
> => { :is_visible => true }) 
> 
> 
> OR
> 
> @project_search = Refinery::Wayfinders::Project.search(params[:search], 
> :include => :is_visible, :conditions => { :is_visible => true })
> 
> 
> Or a third solution?
> 
> 
> Thanks in advance
> 
> 
> Regards 
>  
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Reply via email to