Mercurial > hg > purlService
diff searchService/searchSolr.py @ 20:cf4503528b5e
searchsolr neue function, zun?chst nur f?r text-url-path
author | dwinter |
---|---|
date | Tue, 29 Jan 2013 16:51:28 +0100 |
parents | |
children | 90643ccc6545 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/searchService/searchSolr.py Tue Jan 29 16:51:28 2013 +0100 @@ -0,0 +1,95 @@ +''' +Created on 16.11.2012 + +@author: dwinter +''' + +import solr +import web +import urllib +import os.path +import json +import urllib2 +import logging + +#SOLR_SERVER="https://md.mpiwg-berlin.mpg.de/solr" +SOLR_SERVER="http://127.0.0.1:8983/solr" +DRI_SERVER="http://md.mpiwg-berlin.mpg.de/" + +class searchSolr: + + def __init__(self): + #logging.basicConfig(filename='/tmp/solr.log',level=logging.DEBUG) + self.con = solr.SolrConnection(SOLR_SERVER,debug=False) + + self.search = solr.SearchHandler(self.con,"/collection1/select") + + + def GET(self): + paras = web.input() + + if not hasattr(paras,'text-url-path'): + return "usage: ?text-url-path=PATH" + + if getattr(paras,'format','')== "short": + short=True + else: + short=False + + + queryString=paras.get("text-url-path") + + return self.doGet(queryString,short=short) + + def doGet(self,queryString,short=False): + + queryString="""text-url-path:"%s" """%queryString + response = self.search(queryString) + + ret="" + hitId=0 + rows=[] + + ret="<results>" + + for hit in response: + + ret+="<result>" + + if short: + key="text-url-path" + r=hit.get(key) + ret+="""<%s>%s<%s>"""%(key,r,key) + + else: + + for key in hit.keys(): + res=hit.get(key) + if not isinstance(res, list): + res=[res] + + + + for r in res: + + ret+="""<%s>%s<%s>"""%(key,r,key) + + #ret.append(hit.get('archive-path')) + + ret+="</result>" + + + + return ret+"</results>" + + + + + + +if __name__ == '__main__': + sl = searchSolr() + + x=sl.doGet("/diverse/de/Einst_Bemer_de_1907.xml",short=True) + + print x.encode("utf-8")