2013-12-09 57 views
0

我需要你的帮助。我想在全文太阳黑子搜索中获得匹配的字符串。 那是我的代码如何在目前太阳黑子轨 - 在全文搜索中获得匹配的子字符串

search2 = WebsiteEntry.search do 
    fulltext params[:q] 
    end 

    search2.each_hit_with_result do |hit, res| 
    @match = <Here I need your Help, i need the substring on which sunspot made a hit> 
    @results.push SearchResult.new(res, hit.score, @match) 
    end 
end 

看起来像现在,如果i'm搜索单词“测试”黑子看上去一切,其中“测试”是一个子不区分大小写。 例如:太阳黑子返回匹配的单词“FirstTest”或“TEST2”或“testit”。

是否有可能获得匹配的字符串?我需要太阳黑子击中的字符串

从“FirstTest”需要点击“测试”。因为我想显示太阳黑子创建比赛的地方。所以,从“FirstTest”我需要子字符串“测试”。从“TEST2”我需要“测试”等。

谢谢。

回答

0

我现在已经解决了我的问题。 “命中” - OBJEKT在“each_hit_with_result”函数返回与所匹配的子字符串列表,称为“亮点”

search2 = WebsiteEntry.search do 
    fulltext params[:q] do 
     highlight :domain 
    end 
    end 

    search2.each_hit_with_result do |hit, res| 
    hit.highlight(:domain).format { |word| puts "highlight: "+word} 

没有I'm让每一个匹配字符串形成完整的文本搜索。问题是,我没有把我的属性标记为重点。 Thx