【问题标题】:saving search terms rails thinkingsphinx保存搜索词 rails thinkingsphinx
【发布时间】:2011-03-30 03:59:18
【问题描述】:

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

【问题讨论】:

    标签: ruby-on-rails search sphinx thinking-sphinx


    【解决方案1】:

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

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

    【讨论】:

    • 我使用延迟,但不是出于此目的。我还没有尝试过,但我想知道开始创建延迟作业是否需要不到 0.280 秒。我的问题是了解 Rails 中与搜索相关的一般最佳实践。谢谢你的建议!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 1970-01-01
    • 2015-06-21
    • 1970-01-01
    • 2018-01-12
    相关资源
    最近更新 更多