To reduce server load I'm wanting to start sphinx on demand as I have
over 80 websites all wanting to use sphinx but usually only 10 active
at any one time.
Obviously if ts is not running I get a connection refused exception
from riddle so all I need to do is trap that exception and start the
server.
To achieve this I have the following in a searches controller.
  def index
    @search_results = CustomMenu.search(params[:search], :include
=> :custom_page)
    begin
      if @search_results.blank?
        flash[:notice] = 'Sorry, no search results found'
      end
    rescue Riddle::ConnectionError
      start_search_engine
      @search_results = CustomMenu.search(params[:search], :include
=> :custom_page)
    end
  end

  def start_search_engine
    Search.start_sphinx
  end

and the search module looks like this
class Search
  def self.start_sphinx
    "rake thinking_sphinx:rebuild RAILS_ENV=#{Rails.env}"
    res = "rake thinking_sphinx:start RAILS_ENV=#{Rails.env}"
    puts("@@@@ Start sphinx #{res}")
  end
end
However the start_sphinx method does not actually work though the
output returned in the puts statement shows
@@@@ Start sphinx rake thinking_sphinx:start RAILS_ENV=development but
the connection is refused in the view.

Sphinx will start if I run the rake task from the command line.

Any ideas as to what the best solution for this problem might be would
be greatly appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to