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 use phrase_boundary in SphinxSearch?
- How to configure memory usage in SphinxSearch?
- How to use the SphinxSearch indexer command?
- How to order search results by relevance in SphinxSearch?
- How to specify stop words in SphinxSearch?
- How to use regexp_filter in SphinxSearch?
- How to delete data from a realtime index in SphinxSearch?
- How to use the MySQL protocol in SphinxSearch?
- How to reload the configuration in SphinxSearch?
- How to use sql_attr_json in SphinxSearch?
See more codes...