# HG changeset patch # User dwinter # Date 1351852463 -3600 # Node ID 733d43b30a8216e14a15735c3f7343b2775e9a8b # Parent 78dd28ade713832eff528cc4259ccd8a173066d2 connection handling changed searcher added diff -r 78dd28ade713 -r 733d43b30a82 addDriToIndexMeta.py --- a/addDriToIndexMeta.py Fri Nov 02 09:25:11 2012 +0100 +++ b/addDriToIndexMeta.py Fri Nov 02 11:34:23 2012 +0100 @@ -48,7 +48,7 @@ def addDriToIndexMeta(path,delpath="",replacepath="",test=False): - + md=manageIndexMetaPURLs.IndexMetaPURLManager() for root, dirs, files in os.walk(path): @@ -57,7 +57,7 @@ if name.endswith(".meta"): fl=join(root, name) shortPath=re.sub("^"+delpath,replacepath,fl) - purl=manageIndexMetaPURLs.IndexMetaPURLManager().getPurl(shortPath) + purl=md.getPurl(shortPath) addPURL(fl,purl,test) diff -r 78dd28ade713 -r 733d43b30a82 manageIndexMetaPURLs.py --- a/manageIndexMetaPURLs.py Fri Nov 02 09:25:11 2012 +0100 +++ b/manageIndexMetaPURLs.py Fri Nov 02 11:34:23 2012 +0100 @@ -38,9 +38,9 @@ def __init__(self): - self.purlDB = web.database(dbn="postgres", db="purlDB",user="purlUSER",password="p*lWa55eR", host="localhost") + self.purlDB = web.database(dbn="postgres", db="purlDB",user="purlUSER",password="3333", host="localhost") - + def getPath(self,purl): urls = self.purlDB.select('"purls"' ,where="purl='%s'"%purl) @@ -92,12 +92,22 @@ def getPurl(self,path): #urls = self.purlDB.select('"purls"',where="path=%s"%web.sqlquote(path.replace("'")) urls = self.purlDB.query("select * from purls where path=$path",vars={'path':path}) + if urls is None or len(urls)==0: return None else: return urls[0]['purl'] + + def search(self,query): + purls = self.purlDB.query("select purl from purls where path like $path",vars={'path':query}) + if purls is None or len(purls)==0: + return None + else: + return purls + + def generatePurl(self): diff -r 78dd28ade713 -r 733d43b30a82 restService/restService.py --- a/restService/restService.py Fri Nov 02 09:25:11 2012 +0100 +++ b/restService/restService.py Fri Nov 02 11:34:23 2012 +0100 @@ -7,10 +7,12 @@ import manageIndexMetaPURLs from redirector import redirector import logging +from searcher import searcher urls = ( '/purl/(.+)','purl', '/docuviewer/(.+)','redirector', + '/search','searcher', ) app = web.application(urls, globals()) diff -r 78dd28ade713 -r 733d43b30a82 restService/searcher.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/restService/searcher.py Fri Nov 02 11:34:23 2012 +0100 @@ -0,0 +1,41 @@ +''' +Created on 02.11.2012 + +@author: dwinter +''' + +import web +import manageIndexMetaPURLs + +class searcher: + + def __init__(self): + self.md=manageIndexMetaPURLs.IndexMetaPURLManager() + + def GET(self): + + input = web.input() + + if not hasattr(input, 'q'): + return "usage: ?q=QUERYSTRING" + query = input.q + + purls=self.md.search(query) + + currentUrl = web.ctx.homepath + + if purls is None: + purls=[] + + ret="""
%s
"""%len(purls) + + for purl in purls: + ret+="""
%s
"""%(currentUrl+"/purl/"+purl['purl'],purl['purl']) + + + web.header('Content-Type', 'text/html') + return ret+"
" + + +if __name__ == '__main__': + pass \ No newline at end of file