保存搜索词 Rails Thinkingsphinx

发布于 2024-09-14 14:12:43 字数 1113 浏览 8 评论 0原文

我在 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

I use TS for full text search in my rails app. I am trying to save the search term to present "most searched" type list in my app. Here is my search controller index action. I notice that with the "save" the search feature the search takes about 1.28s and without it about 1.04s.

Couple of questions.

1- Is there a better way to do this, so that I don't add the extra time to the search?

2 - What's in general the best way to speed up full text searching outside of following the standard best practices of TS or Sphinx i.e is there any kind of caching or something like that?

Thanks

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴梦长久 2024-09-21 14:12:43

大声思考,也许您可​​以使用 Delayed::Job 在幕后保存搜索词。在我看来,当你编译自己的统计数据时,没有人真的应该等待他们的搜索结果。请注意,这仍然只有 0.280 秒。

如果您不熟悉的话,请查看 tobi's Late job on github

Thinking out loud, maybe you can use Delayed::Job to save the search term, behind the scenes. No one really should have to wait for their search results while you compile your own stats, imo. mind you it's only .280 of a second, still.

check out tobi's delayed job on github if you are unfamiliar with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文