本文整理汇总了Python中solr.SolrConnection.search方法的典型用法代码示例。如果您正苦于以下问题:Python SolrConnection.search方法的具体用法?Python SolrConnection.search怎么用?Python SolrConnection.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类solr.SolrConnection
的用法示例。
在下文中一共展示了SolrConnection.search方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: oralookup
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import search [as 别名]
def oralookup(
pid=None,
uuid=None,
fields_to_return="f_name, f_subject, f_keyphrase, faculty, f_institution, thesis_type, content_type, collection",
):
s = SolrConnection("ora.ouls.ox.ac.uk:8080")
results = {}
query = ""
if pid:
pid = "\:".join(pid.split(":"))
query = "id:%s" % pid
elif uuid:
query = "id:uuid\:%s" % uuid
else:
return results
# Running actual query (3 tries, failover)
tries = 0
while tries != 3:
try:
r = s.search(q=query, wt="json", fl=fields_to_return)
logger.debug("Solr response: %s" % r)
tries = 3
except BadStatusLine:
sleep(0.5)
tries = tries + 1
try:
results = simplejson.loads(r)
assert results["response"]["numFound"] == 1
return results["response"]["docs"][0]
except ValueError:
logger.warn("Couldn't parse json response from Solr endpoint: %s" % r)
return {}
except AssertionError:
logger.warn("Couldn't assert that only a single result was fetched: %s" % results)
return {}
示例2: main
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import search [as 别名]
def main():
opts, args = parse_opts()
logging.basicConfig(filename=opts.log_file, level=logging.DEBUG,
format='[%(asctime)s|%(levelname)s|%(name)s|%(threadName)s|%(message)s]')
solr = SolrConnection(opts.solr_uri)
protocol = LineProtocol()
for request in protocol.input():
try:
query = build_query(request)
if query is None:
protocol.output(query_failed(), True)
continue
log.debug("Running query: " + str(query))
results = solr.search(**query)
if results is None:
protocol.output({'code' : 400})
continue
resp = json.loads(results)
ret = {
'code' : 200,
'json' : resp['response']
}
protocol.output(ret, True)
except Exception:
log.exception("Uncaught exception")
return 0
示例3: titlelookup
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import search [as 别名]
def titlelookup(pid):
s = SolrConnection("ora.ouls.ox.ac.uk:8080")
results = {}
query = ""
if pid:
pid = "\:".join(pid.split(":"))
query = "id:%s" % pid
elif uuid:
query = "id:uuid\:%s" % uuid
else:
return results
# Running actual query (3 tries, failover)
tries = 0
while tries != 3:
try:
r = s.search(q=query, wt="json", fl="title")
logger.debug("Solr response: %s" % r)
tries = 3
except BadStatusLine:
sleep(0.5)
tries = tries + 1
try:
results = simplejson.loads(r)
assert results["response"]["numFound"] == 1
doc = results["response"]["docs"][0]
return doc["title"]
except ValueError:
logger.warn("Couldn't parse json response from Solr endpoint: %s" % r)
return {}
except AssertionError:
logger.warn("Couldn't assert that only a single result was fetched: %s" % results)
return {}
示例4: __init__
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import search [as 别名]
class MLGBsolr:
def __init__(self):
self.s_result = ()
self.conn = None
self.connstatus = False
self.req = None
def solrconn( self, core = 'books' ):
try:
solr_base_and_core = "%s/%s" % (solr_base, core)
self.conn = SolrConnection( host=solr_host, solrBase=solr_base_and_core, \
username=solr_uname, password=solr_pswd )
self.connstatus=True
return True
except:
#print "solr connection error!"
return False
def solrquery( self, para, core = 'books' ):
if self.solrconn( core ):
try:
self.search = self.conn.search( para )
self.connstatus=True
return True
except:
#print "solr query failed!"
return False
def solrresults( self, para, Facet = False, core = 'books' ):
if self.solrquery( para, core ):
rsp = simplejson.loads( self.search )
s_numFound = rsp[ 'response' ].get( 'numFound', None )
s_docs = rsp[ 'response' ].get( 'docs', None )
s_params = rsp[ 'responseHeader' ].get( 'params', None )
s_rows = s_params.get( 'rows', None )
s_start = s_params.get( 'start', None )
s_q = s_params.get( 'q', None )
if Facet :
s_facet_fields=rsp['facet_counts'].get( 'facet_fields', None )
self.s_result = {'numFound' : s_numFound,
'search_params': s_params,
'query' : s_q,
'start' : s_start,
'rows' : s_rows,
'docs' : s_docs
}
if Facet :
self.s_result['facet'] = s_facet_fields
def __unicode__(self):
return self.s_result