The Sphinx application includes a Python API interface that allows you to perform searches and return results in Python programs. All of the API commands are defined in the Sphinx documentation, but their specific usage within Python can vary.
We will take a quick tour of the Sphinx Python API and then discuss how it can be integrated into our Django models. First, a simple Python snippet that generates the interface to a Sphinx server running on our local machine:
SERVER = 'localhost' PORT = 5555 client = sphinxapi.SphinxClient() client.setServer(SERVER, PORT)
Now we have a client object that exposes the API listed in the Sphinx documentation. We can perform simple operations, like queries, using this client. To replicate the command line we used in the previous section, we could issue the following Python command:
results = client.Query('cranberry juice')
If we need to specify the index or indexes to use, we can pass them as a string containing the index names separated...