sphinx-searchExample of sphinxsearch usage in Python
SphinxSearch is a powerful full-text search engine written in C++. It can be used in Python applications to provide fast and accurate search results.
Example code
import sphinxapi
# Create a SphinxClient object
client = sphinxapi.SphinxClient()
# Set the server, port, and search query
client.SetServer('localhost', 9312)
client.SetMatchMode(sphinxapi.SPH_MATCH_EXTENDED2)
client.Query('python')
# Get the results
results = client.GetMatches()
# Print the results
for result in results:
print(result)
Output example
{'weight': 1, 'attrs': {}, 'id': 1, 'matches': [{'weight': 1, 'id': 1, 'word': 'python'}]}
The code above creates a SphinxClient object, sets the server, port, and search query, and then gets the results. The results are then printed.
Parts of the code:
import sphinxapi
: imports the SphinxSearch API for Pythonclient = sphinxapi.SphinxClient()
: creates a SphinxClient objectclient.SetServer('localhost', 9312)
: sets the server and portclient.SetMatchMode(sphinxapi.SPH_MATCH_EXTENDED2)
: sets the search queryclient.Query('python')
: sets the search queryresults = client.GetMatches()
: gets the resultsfor result in results:
: iterates through the resultsprint(result)
: prints the results
Helpful links
More of Sphinx Search
- How to reload the configuration in SphinxSearch?
- How to query a specific index in SphinxSearch?
- How to use SphinxSearch with PHP?
- How to delete an index in SphinxSearch?
- How to offset results in SphinxSearch?
- How to get the version of SphinxSearch?
- How to configure memory usage in SphinxSearch?
- How to use sql_attr_float in SphinxSearch?
- How to delete data from a realtime index in SphinxSearch?
- How to use query_log_format in SphinxSearch?
See more codes...