Sphinx 高亮实现

在配置environment中加入
Ultrasphinx::Search.excerpting_options =
HashWithIndifferentAccess.new({
:before_match => '',
:after_match => '
',
:chunk_separator => "...",
:limit => 256,
#s:around => 2, # This doesn't seem to work.
:content_methods => [['title'], ['body', 'description', 'content']]

})

在搜索的article.rb中修改搜索方法
def self.my_search(search)
# find(:all, :conditions => ['body LIKE ? OR title LIKE ? OR description LIKE ?', "%#{search}%","%#{search}%","%#{search}%"])
my_search_result = Ultrasphinx::Search.new(:query=>search)
my_search_result.run
my_search_result.excerpt
end
最后返回的是excerpt

测试
a=Ultrasphinx::Search.new(:query=>'new')
a.run
a.excerpt

你可能感兴趣的:(ROR)