Save search terms rails thinkingsphinx

I use TS for full-text search in my rails application. I am trying to save a search query to present a list of "most searched" in my application. Here is my search controller index action. I notice that when you "save" the search function, the search takes about 1.28 s and without it about 1.04.

A few questions.

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

2 - What is generally the best way to speed up full-text search beyond standard TS or Sphinx standard methods. Is there any caching or something like that?

thank

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
+3
source share
1

, , Delayed:: Job, , . , , imo. .280 , .

github, .

+1

Source: https://habr.com/ru/post/1759795/


All Articles