Python Client API
Solr also comes with APIs that can be connected through applications developed in the Python programming language. Solr supports responses in Python format, which can be easily interpreted in Python programming. As we have seen before for JavaScript, SolrJ, and Ruby, Python also provides all the required packages to perform search, add, delete and so on.
Let's start with search. Here is the simple search configuration for searching a query q=ipod
in techproducts
:
import urllib.request connection = urllib.request.urlopen('http://localhost:8983/solr/techproducts/select?q=ipod&fl=id,name&wt=python') response = eval(connection.read()) print(response)
Response:
{'responseHeader': {'status': 0, 'QTime': 51, 'params': {'q': 'ipod', 'fl': 'id,name', 'wt': 'python'}}, 'response': {'numFound': 3, 'start': 0, 'docs': [{'id': 'IW-02', 'name': 'iPod & iPod Mini USB 2.0 Cable'}, {'id': 'F8V7067-APL-KIT', 'name': 'Belkin Mobile Power Cord for iPod w/ Dock'}, {'id': 'MA147LL...