Sphinx Search Using PHP on Windows

Omolara Adejuwon
Larikraun’s Blog
Published in
2 min readJan 15, 2016

There is this new thing I picked up. It is called SPHINX. Sphinx is an open source full text search server, designed from the ground up with performance, relevance (aka search quality), and integration simplicity in mind. You can check the features from their site. I am not trying to promote sphinx but I can say boldly that it is very much easy to install.

Some other highlights are:

  • Another interesting thing about sphinx is that it has been ported to some languages and this is where SphinxAPI comes in. SphinxAPI is a native library available for Java, PHP, Python, Perl, C, and other languages.
  • When you have decided that you want try sphinx out, download the latest release for your system specifications here and let us proceed with installation.

INSTALLATION

  • Extract the .zip file to a preferred folder. If you look through the contents of the folder, you will find an example.sql file and some other config files. These are to make testing, tour and usage easier.
  • To make our folder less dirty, we will create two new folders ourselves.
  • Create data and log folders. Index files will be saved in data while stuff will be logged into the log folder.

Then open the sphinx.conf.in the find and replace @CONFDIR@ to a preferred path (e.g C:/Sphinx) also check the database parameters. Edit the user to your user e.g root and supply the password.

From your command prompt, cd to the sphinx folder and run
bin\searchd --install --config path\to\sphinx\sphinx.conf.in --servicename SphinxSearch.
This command installs and starts the SphinxSearch service.
If you got this error FATAL: OpenSCManager() failed: code=5, error=Access is denied, then make sure your command prompt was run as an administrator.
Now that we have the success message, let's move on.

DATABASE AND TABLES
Create a test table in your database. This is the table that will be used in the example.sql included in the folder downloaded. You can open and view the queries in it.
Import the example.sql into your test database.

INDEXING
Now we will create our index files. How? Just by running another command on your cmd.
bin\indexer --config path\to\sphinx\sphinx.conf.in --all
SEARCHING
Create a php script in your C:/xampp/htdocs/folderName.
Copy and paste the snippet below

Run the script from the browser like this localhost/folderName/sphinxtest.php?q=test

That is it about installing and using sphinx.

You can tell that there are still many more things to do, right? There are still other tweaks that we need to include in our configuration file and script. But as I mentioned, I picked sphinx up about two days ago. Therefore, there is still so much for me to learn and share about sphinx. Till then, drop your comments.

--

--

Omolara Adejuwon
Larikraun’s Blog

Code and everything in between. Android Engineer. Editor @proandroiddev