def SolrQuery(query_filter = "" , q = "*:*" , req_format="json", type="dataset"): numFound=0 solr_params = {} solr_params['q'] = q.encode('utf-8')+query_filter+ " AND type:"+type solr_params['wt'] = req_format try: solr_conn = SolrConnection("http://10.0.0.154:8081/solr") solr_response = solr_conn.raw_query(**solr_params) #print solr_response search = json.loads(solr_response) solr_reponse = search['response'] #print solr_response numFound = 0 if 'numFound' in solr_reponse: numFound = solr_reponse.get('numFound',0) print numFound except: traceback.print_exc() print "exception" pass return (solr_response,numFound)
import json import codecs solrhost = "http://localhost:8080/solr" s = SolrConnection(solrhost) fieldnames = ['silo', 'id', 'uuid', 'aggregatedResource', 'created', 'creator', 'currentVersion', 'date', 'dateAccepted', 'dateCopyrighted', 'dateSubmitted', 'description', 'embargoStatus', 'embargoedUntilDate', 'mediator', 'isPartOf', 'isVersionOf', 'license', 'modified', 'publisher', 'rights', 'subject', 'timestamp', 'title', 'type'] solr_params = {} solr_params['q'] = "silo:digitalbooks" solr_params['wt'] = 'json' solr_params['fl'] = ','.join(fieldnames) solr_params['rows'] = 500000 solr_params['start'] = 0 solr_response = s.raw_query(**solr_params) numFound = 0 docs = None fname = "digitalbooks.csv" delimiter = '$' if solr_response: ans = json.loads(solr_response) numFound = ans['response'].get('numFound',None) try: numFound = int(numFound) except: numFound = 0 docs = ans['response'].get('docs',None) if numfound > 0 and docs: