Hello,
I am doing a search across different models, and I want to show the
excerpts of the results using excerpt_for:

In my controller I have:
    @search_results = ThinkingSphinx.search(params[:q],
                                     :classes => [ Content,
NewsItem ],
                                      :page => params[:page],
                                     :per_page => 5,
                                     :order => :created_at,
                                     :sort_mode => :desc,
                                     :match_mode => :boolean,
                                     :field_weights => { :name =>
20, :body => 10})

In my view I have:
<% @search_results.each do |result| %>
<%= @search_results.excerpt_for(result.body) %>
<% end %>

And it fails:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.source_of_sphinx_index

/home/baptiste/repos/projects/trunk/opengate_users/vendor/plugins/
thinking-sphinx/lib/thinking_sphinx/search.rb:212:in `excerpt_for'
/home/baptiste/repos/projects/trunk/opengate_users/app/views/searches/
create.html.erb:30:in
`_run_erb_app47views47searches47create46html46erb'
/home/baptiste/repos/projects/trunk/opengate_users/app/views/searches/
create.html.erb:20:in
`_run_erb_app47views47searches47create46html46erb'
/home/baptiste/repos/projects/trunk/opengate_users/app/controllers/
searches_controller.rb:7:in `show'

If in my controller I do my search on only one class it works.

I do not use result.excerpts.body because I want to manually truncate
the body using truncate_html, in order to ovoid html tags breaks.

Thanks,
Baptiste

--~--~---------~--~----~------------~-------~--~----~
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