SOLR-11319: bring python with json docs up to date. This closes #243

This commit is contained in:
Cassandra Targett 2017-10-19 15:41:38 -05:00
parent ae72dbd635
commit b7a53012ed
1 changed files with 4 additions and 9 deletions

View File

@ -51,21 +51,16 @@ for document in response['response']['docs']:
== Python with JSON == Python with JSON
JSON is a more robust response format, but you will need to add a Python package in order to use it. At a command line, install the simplejson package like this: JSON is a more robust response format, and Python has support for it in its standard library since version 2.6.
[source,bash] Making a query is nearly the same as before. However, notice that the `wt` query parameter is now `json` (which is also the default if no `wt` parameter is specified), and the response is now digested by `json.load()`.
----
sudo easy_install simplejson
----
Once that is done, making a query is nearly the same as before. However, notice that the wt query parameter is now json (which is also the default if not wt parameter is specified), and the response is now digested by `simplejson.load()`.
[source,python] [source,python]
---- ----
from urllib2 import * from urllib2 import *
import simplejson import json
connection = urlopen('http://localhost:8983/solr/collection_name/select?q=cheese&wt=json') connection = urlopen('http://localhost:8983/solr/collection_name/select?q=cheese&wt=json')
response = simplejson.load(connection) response = json.load(connection)
print response['response']['numFound'], "documents found." print response['response']['numFound'], "documents found."
# Print the name of each document. # Print the name of each document.