ruby on rails - Thinking Sphinx :sort_mode => :time_segments or :sort_mode => :expr with @weight*created_at? -
i'm studding sphinx , thinking-sphinx , need opinion , help, want following:
i have list of news (noticias) , want order results date , relevance because if search doesn't matter when news created query won't take in consideration. if specify @ least closer year or year , month have more relevance question should solved.
i saw lot of things not conclusive, maybe low experience sphinx , thinking-sphinx.
how can solve problem? how think best way? thanks.
my model:
define_index indexes :titulo indexes :chamada indexes :texto indexes :description indexes :keywords indexes :otimizador_de_busca indexes :created_at, :sortable => true indexes tags.nome, :as => :tag indexes usuario.nome, :as => :autor "validacao = '1'" end
my search function on controller:
termo = params[:termo].first(50) @noticias = noticia.search termo, :field_weights => {:tag => 150, :autor => 120, :titulo => 100, :chamada => 80, :otimizador_de_busca => 65, :description => 50, :keywords => 50, :texto => 10}, :match_mode => :all, :page => params[:pagina], :sort_mode => :extended, :order => "@relevance desc, created_at desc", :per_page => 15
a few things note. firstly, there's difference between fields , attributes sphinx, , there's not gained having created_at field, it's far more useful attribute (which natively sortable). so, let's update index definition:
define_index indexes :titulo indexes :chamada indexes :texto indexes :description indexes :keywords indexes :otimizador_de_busca indexes tags.nome, :as => :tag indexes usuario.nome, :as => :autor has :created_at "validacao = '1'" end
and run rake ts:rebuild
change reflected in index files , sphinx daemon aware of too.
as how you're sorting... you've got few options. in example, you're sorting relevance, matching relevance scores has newer items listed first. think that'll work quite well.
if want use sphinx's time_segments sorting, might work well, it'll group results first age (without being specific), , automatically orders within each age group relevance:
termo = params[:termo].first(50) @noticias = noticia.search termo, :field_weights => {:tag => 150, :autor => 120, :titulo => 100, :chamada => 80, :otimizador_de_busca => 65, :description => 50, :keywords => 50, :texto => 10}, :match_mode => :extended, :page => params[:pagina], :sort_mode => :time_segments, :order => :created_at, :per_page => 15
i've changed match mode extended, i'd recommend.
finally, you've suggested, factor in created_at timestamp relevance in expression - that's you. there's formulas out there that, think that's complexity don't need.
if think it's more important have newer results first, use time segments. if think it's more important have relevant results search query first, use extended sort mode in own example. think 1 better, it's you.
Comments
Post a Comment