我在 Rails 应用程序中使用 TS 进行全文搜索。我正在尝试保存搜索词以在我的应用程序中显示“搜索最多”类型列表。这是我的搜索控制器索引操作。我注意到,使用“保存”搜索功能,搜索大约需要 1.28 秒,而没有它大约需要 1.04 秒。
几个问题。
1-有没有更好的方法来做到这一点,这样我就不会在搜索中增加额外的时间?
2 - 除了遵循 TS 或 Sphinx 的标准最佳实践之外,加速全文搜索的最佳方式通常是什么,即是否有任何类型的缓存或类似的东西?
谢谢
def index
terms = params[:search_term]
terms ||= ""
if params[:city]
@search_results = Post.search terms, :conditions => {:city => params[:city]}, :page => params[:page] || 1, :per_page => Constants::LISTINGS_PER_PAGE
elsif params[:state]
@search_results = Post.search terms, :conditions => {:state => params[:state]}, :page => params[:page] || 1, :per_page => Constants::LISTINGS_PER_PAGE
else
@search_results = Post.search terms, :page => params[:page] || 1, :per_page => 3
end
# if @search_results.total_entries > 0
# Search.create(:term => terms)
# end
respond_to do |format|
format.html
format.js
end
end