Sphinx connection error on search results page in Ruby on Rails application

I have a RoR application with a Posgresql database. I am trying to customize a search function using Sphinx as my search engine and the Thinking Sphinx gem. I have installed sphinx with mysql and postgresql support, thinking about the sphinx v3 gem and its dependencies.

Command

rake ts: index

makes mistakes. The magazine says I have 20 documents indexed (all my Post model entries). Then I tried to create a controller and view the search results page. Here's the controller search action

def search
    @query = Riddle::Query.escape(params[:q])
    @posts = Post.search(@query)
end

      

And when i try to use @posts variable in search view

local: 3000 / search q = hi

I have the following error.

ThinkingSphinx :: ConnectionError in main # search

Error connecting to Sphinx via MySQL protocol. Error connecting to Sphinx via MySQL protocol. Unable to connect to MySQL server at "127.0.0.1" (61) - SELECT * FROM post_core

WHERE MATCH ('hello') AND sphinx_deleted

= 0 LIMIT 0, 20; SHOW META

+3


source to share


3 answers


The task ts:index

just stores the Sphinx data, it doesn't start a daemon that responds to search queries. To do this, you need to run ts:start

rake command .



Also: ts:rebuild

does it all at once: stops Sphinx (if it is running), indexes the data, starts Sphinx.

+5


source


Thinking Sphinx uses mysql for its internal purposes and you need to add a mysql2

gem to your stack like:



gem 'mysql2', '~> 0.3.13'
gem 'thinking-sphinx', '~> 3.1.1'

      

+1


source


I generally got stuck and faced the same error. Finally, I found that I did not install "Sphinx" on my local system with this command,

sudo apt-get update
sudo apt-get install sphinxsearch

      

You can find more details about installation here

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-sphinx-on-ubuntu-14-04

Make sure you also have to install "mysql-server" on your system to create a connection.

Also I looked that @blelump's answer was my second step. You must include these gems in order to work with the sphinx.

Then move on to @pat's answer, this is my final step. When you have installed sphinx, it will start the service, but you need to stop running the service,

rake ts:index
rake ts:rebuild

      

Here to go with SPHINX.

0


source







All Articles