I'm using sphinx with rails, and it seems that aside from the columns I have specified as indexes, Sphinx also searches against the Model name, and adds it to the list of excerpt words.
So for example, I have a model called 'Event'. If I search for 'Dance', my results will also have the word 'event' highlighted if it occurs in any of the indexed fields, ie 'Dance Event' will be highlighted, instead of just 'Dance'. Any idea how I can stop this behaviour?
EDIT:
Edit: I realized that this was not happening in the search-autocomplete window, as the ajax-y search route searched differently :
results = ThinkingSphinx.search(params[:search], {:star => true})
results.context[:panes] << ThinkingSphinx::Panes::ExcerptsPane
And the search result with incorrect excerpts are on particular models (see below)
Here's the code, :
event_index.rb
ThinkingSphinx::Index.define :event, :with => :active_record do
indexes title
indexes subtitle
indexes vendor.name, :as => :event_vendor
indexes vendor.city, :as => :event_city
indexes genre.name, :as => :genre_name
set_property :min_prefix_len => 3
set_property :enable_star => true
end
vendor_index.rb
ThinkingSphinx::Index.define :vendor, :with => :active_record do
indexes :name
indexes city, :as => :city
set_property :min_prefix_len => 3
set_property :enable_star => true
end
search_controller.rb
def index
@events = Event.search params[:search], {:star => true , :per_page => 5, :page => params[:events_page]}
@events.context[:panes] << ThinkingSphinx::Panes::ExcerptsPane
@vendors = Vendor.search params[:search], {:star => true , :per_page => 5, :page => params[:vendors_page]}
@vendors.context[:panes] << ThinkingSphinx::Panes::ExcerptsPane
end
and a event result partial, _event.html.erb
<div class="event">
<table>
<tr>
<td class="image">
<% if event.image? %>
<%= image_tag event.image_url(:mid).to_s %>
<% else %>
<img src='http://lorempixel.com/100/100/abstract/<%= (1..10).to_a.sample %>' />
<% end %>
<div class="genre_img">
<%= image_tag event.genre.image_url().to_s %>
</div>
</td>
<td class="body">
<%= event.excerpts.to_yaml %>
<h3><%= link_to ( raw event.excerpts.title), event_path(event) %></h3>
<p class="bold"> <%= raw event.excerpts.subtitle %> </p>
<p class="bold"> Genre: <%= raw event.excerpts.genre_name %> </p>
<p class="bold"><%= link_to ( raw event.excerpts.vendor_name), vendor_path(event.vendor) %></p>
<p class="bold"> <%= raw event.excerpts.vendor_city %> </p>
</td>
</tr>
</table>
</div>
I've looked around a bit and can't seem to figure it out - I'm sure there's an option somewhere I'm missing. Any help would be appreciated, thank you!
As per the documentation (TS ~> 3.0.0), there's two ways to add an excerpts - through a pane or by creating an object.
For some reason, the first approach will include class/model names as matches, while the second doesn't. So this works:
@event_excerpter = ThinkingSphinx::Excerpter.new 'event_core',
params[:query]
and in the view
<h3><%= @event_excerpter.excerpt! event.title %></h3>
(also worth noting that passing an excerpter as a local to a partial does not seem to work)