Hi Keith Sorry for the delay in the response on this issue... ideally, you should never get nil results, because Thinking Sphinx updates the indexes accordingly when a result is removed from the database.
It looks like you're not actually deleting products from the database though - just setting deleted_at to NULL. Are you using a third-party library (acts as paranoid or similar) to do this? This is my guess of the situation: * You're 'deleting' products - which remain in the database, but the default find calls won't find them. * When these products get returned by Sphinx, it can't instantiate them because of this. What you'll need to do is call toggle_deleted on a product when you delete it - this will update Sphinx accordingly, and you should no longer get the nil results. Let me know how this goes. Cheers -- Pat On 11/12/2010, at 2:26 AM, keith wrote: > Hi All, > > I'm getting an error when I try to run (in script/console on Rails > 2.3.5): > >>> Product.facets "foobar" > NoMethodError: undefined method `sphinx_facets' for nil:NilClass > > After some inspection, it seems this is because in Thinking- > sphinx-1.3.11/lib/thinking_sphinx/facet_search.rb, in the > add_from_results method, there is the following line: > > facet = facet_from_object(results.first, facet) if facet.is_a?(String) > > However, the results set has a nil value as its first value. The > results set was defined in the same file in the populate method: > > ThinkingSphinx.search(*(args + [search_options])) > > So I'm not sure exactly where things are going wrong. Is there ever > supposed to be nil values in this result set? If so, is TS not being > defensive enough? If not, does that mean my index is faulty? > (Included below.) > > > Thank you so much, its been a day and I am really not sure which > direction to take. Happy to answer any questions. > > Keith > > Here is my define_index for the Product model: > > define_index do > indexes :textile_description > indexes :tags_delimited > indexes :name > indexes :name, :as => :name_sortable, :sortable => true > indexes user(:first_name), :as => :user_first_name > indexes user(:last_name), :as => :user_last_name > indexes manufacturer(:name), :sortable => true, :as > => :manufacturer_name_sortable > indexes manufacturer(:name), :as => :manufacturer_name > has :user_id > has :updated_at > has manufacturer(:id), :as => :manufacturer_id, :facet => true > has product_cat(:first_category_id), :as > => :prod_cat_first_category_id, :facet => true > has product_cat(:second_category_id), :as > => :prod_cat_second_category_id, :facet => true > has product_cat(:third_category_id), :as > => :prod_cat_third_category_id, :facet => true > has product_cat(:fourth_category_id), :as > => :prod_cat_fourth_category_id, :facet => true > > where "products.deleted_at IS NULL" > end > > And just for completeness, here is the error stack involving TS: > > NoMethodError: undefined method `sphinx_facets' for nil:NilClass > > [GEM_ROOT]/gems/thinking-sphinx-1.3.11/lib/thinking_sphinx/ > facet_search.rb:133:in `facet_from_object' > > [GEM_ROOT]/gems/thinking-sphinx-1.3.11/lib/thinking_sphinx/ > facet_search.rb:111:in `add_from_results' > > [GEM_ROOT]/gems/thinking-sphinx-1.3.11/lib/thinking_sphinx/ > facet_search.rb:49:in `populate' > > [GEM_ROOT]/gems/thinking-sphinx-1.3.11/lib/thinking_sphinx/ > facet_search.rb:47:in `each' > > [GEM_ROOT]/gems/thinking-sphinx-1.3.11/lib/thinking_sphinx/ > facet_search.rb:47:in `populate' > > [GEM_ROOT]/gems/thinking-sphinx-1.3.11/lib/thinking_sphinx/ > facet_search.rb:13:in `initialize' > > [GEM_ROOT]/gems/thinking-sphinx-1.3.11/lib/thinking_sphinx/ > search_methods.rb:422:in `new' > > [GEM_ROOT]/gems/thinking-sphinx-1.3.11/lib/thinking_sphinx/ > search_methods.rb:422:in `facets' > > -- > 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.
