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
respond_to do |format|
format.html
format.js
end
end
source
share