Apologies for deleting the original message; I had intended on posting
an updated version to be more accurate in describing the problem.
(you can find the original in Pat's quoted text)
This is related to the development mode in Rails, but the actual
problem seems to be related to the :classes option of facet searches.
Here's what I've found:
When the models are first loaded, the sphinx_facets are added on the
class. When the next request comes and the models are reloaded, this
doesn't seem to happen, or maybe it happens at the wrong time. In any
event, if you pass a class in the options for ThinkingSphinx.facets
like so: ThinkingSphinx.facets('some query', :classes => [User]) then
you're passing a User class that hasn't had its sphinx_facets
populated. So when facet_search.rb's facet_classes method does this:
(
options[:classes] || ThinkingSphinx.indexed_models.collect { |
model|
model.constantize
}
).select { |klass| klass.sphinx_facets.any? }
it ends up with nils that choke the .any? method
There's a quick hack to fix this if you add
options[:classes].map!{|x| x.to_s.constantize} if options[:classes]
as the first line in the facet_classes method. This is (somehow) able
to retrieve classes that have had their sphinx_facets populated.
Now, I'm not sure why this works the way it does, but hopefully this
gets us moving in the right direction for fixing the problem. I'll be
happy to help test any potential fixes to this. Thanks
On Aug 3, 2:49 pm, Pat Allan <[email protected]> wrote:
> And bugs like these show that I don't use TS in production myself ;)
>
> As far as I'm concerned, reloading means re-evaluating the model,
> taking note of changes, so the define_index block should be re-
> evaluated as well. Feel free to hunt down the bug and patch - I'm not
> going to get to it tonight. Will try to spend some time on it tomorrow
> if I can though.
>
> Cheers
>
> --
> Pat
>
> On 03/08/2009, at 8:38 PM, Jeffrey Chupp wrote:
>
>
>
>
>
> > It seems that reloading models in development mode breaks facets. If
> > i do ThinkingSphinx.facets(params[:q]) once, everything is fine, but
> > subsequent calls to that method in development mode raises the
> > following NoMethodError
>
> > You have a nil object when you didn't expect it!
> > You might have expected an instance of Array.
> > The error occurred while evaluating nil.any?
>
> > vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet_search.rb:
> > 70:in `facet_classes'
> > vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet_search.rb:
> > 69:in `select'
> > vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet_search.rb:
> > 69:in `facet_classes'
> > vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet_search.rb:
> > 74:in `all_facets'
> > vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet_search.rb:
> > 82:in `facet_names_for_all_classes'
> > vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet_search.rb:
> > 93:in `facet_names_common_to_all_classes'
> > vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet_search.rb:
> > 28:in `facet_names'
> > vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet_search.rb:
> > 45:in `populate'
> > vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet_search.rb:
> > 11:in `initialize'
> > vendor/plugins/thinking-sphinx/lib/thinking_sphinx/search_methods.rb:
> > 404:in `new'
> > vendor/plugins/thinking-sphinx/lib/thinking_sphinx/search_methods.rb:
> > 404:in `facets'
> > app/controllers/search_controller.rb:19:in `show'
> > /opt/local/bin/mongrel_rails:19:in `load'
> > /opt/local/bin/mongrel_rails:19
>
> > I'm sure I can find a way to fix this, but in thinking about patching
> > it, I'm curious if re-evaluating the define_index block on each
> > request is intentional or not? Should the goal be to make it reload
> > and define the facets properly or should the goal be to skip the
> > define_index call if reloading the model?
>
> > thanks
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---