Skip to content

Instantly share code, notes, and snippets.

@Marchino
Created November 29, 2011 09:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marchino/1404085 to your computer and use it in GitHub Desktop.
Save Marchino/1404085 to your computer and use it in GitHub Desktop.
indexing config
class Controller < ApplicationController
@items = Sunspot.search(ModelName) do
fulltext params[:q], :fields => ["description_#{I18n.locale}".to_sym, :author]
end
end
class ModelName < ActiveRecord::Base
searchable :auto_index => false, :auto_remove => false, :if => :is_indexable? do
text :author, :stored => true, :boost => 1.0, :more_like_this => true
text :description_it, :stored => true, :boost => 1.0, :more_like_this => true do
self.whatever_gives_the_italian_description
end
text :description_en, :stored => true, :boost => 1.0, :more_like_this => true do
self.whatever_gives_the_english_description
end
end
<ul>
<% @items.each_hit_with_result do |hit, item| %>
<li>Autore: <%= hit.stored(:author) %></li>
<li>Descrizione: <%= hit.stored("description_#{I18n.locale}".to_sym) %></li>
<% end %>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment