Sphinx API – The basics part 1
by Stii
You’ve set up Sphinx Search and everything seems to be running smooth.
Now you have to put it to work. This is where the API comes into play! All the API does is it lets you communicate with the indexes you’ve created. Various programming languages are supported like: JAVA, Python, PHP and Ruby. (NOTE: The Ruby on Rails community wrote some plugins for Rails for the Ruby API.)
Lets look at the PHP version. The API is basically a PHP class you can create an instance of and then use the various methods to interact with the search daemon.
First you need to add the file called sphinxapi.php to your include path. In your application, require the sphinxapi.php file:
require_once "/path/to/sphinxapi.php";
Next, create a new instance:
$sphinx = new SphinxClient();
Specify your server and port settings where your search daemon is running on:
$sphinx->SetServer( "localhost", 3312 );
Now, you’re all good to go and ready to start query the indexes. More on that in the next Sphinx Search API post.