Hi Jon

Thanks for pointing out the bug, finding the reason, and offering a patch!

I've reworked things slightly - going up the superclass chain as much as 
necessary to find the facets...
http://github.com/freelancing-god/thinking-sphinx/commit/d7a527b2558eaea60a38a0566d218a297b26dae6
This will be included in the next gem release :)

Thanks again for the help.

-- 
Pat

On 17/07/2010, at 6:56 AM, Jon wrote:

> Hi Pat,
> 
> I have a couple of STI models that aren't working with facet searches.
> 
> They look like:
> 
> class Medium < ActiveRecord::Base
>  define_index do
>    ...
>    indexes :type, :facet => true
>    ...
>  end
> end
> 
> class Video < Medium; end
> class Document < Medium; end
> class Story < Document; end
> class Joke < Document; end
> 
> etc.
> 
> When I try to do a Medium.facet 'foo' I get an exception thrown on
> line 113 of facet_search.rb (on version 1.3.18) because the facet
> returned by #facet_from_object is nill.  Seems that all the classes
> that inherit from Medium have an empty array returned by
> #sphinx_facets. The Medium object has the :type_facet in the array
> from #sphinx_facets.
> 
> I've monkey patched TS with the following, and it seems to work (our
> models only have 1 index each), but I haven't looked much at TS's
> innards, so if you have a better solution, please let me know:
> 
> class ThinkingSphinx::FacetSearch
>  def facet_from_object(object, name)
>    if object.sphinx_indexes.first.model != object.class
>      faceted_object = object.sphinx_indexes.first.model
>    end
>    faceted_object.sphinx_facets.detect { |facet| facet.attribute_name
> == name }
>  end
> end
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to