迴圈查詢一個列表中詞的個數:
#coding=utf-8 import requests ls = [u'我', u'是', u'一個', u'天才', u'你', u'也是'] for item in ls: url = 'http://*IP*:8985/solr/*集合名*/select?q=*欄位名*:"\%s"&wt=json&indent=true'%item r = requests.get(url, verify = False) r = r.json()['response']['numFound'] print item +":"+ str(r)
插入一條資料:
#coding=utf-8 import json import requests data = {"add":{ "doc":{"id":"100001","*欄位名*":u"我是一個大好人"}}} params = {"boost":1.0,"overwrite":"true","commitWithin":1000} url = 'http://*IP*:8985/solr/*集合名*/update?wt=json' headers = {"Content-Type": "application/json"} r = requests.post(url, json = data, params = params, headers = headers) print r.text