开发者

saving search terms rails thinkingsphinx

开发者 https://www.devze.com 2023-01-11 10:42 出处:网络
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 \

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 se开发者_开发问答arch 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消