changeset 8:733d43b30a82

connection handling changed searcher added
author dwinter
date Fri, 02 Nov 2012 11:34:23 +0100
parents 78dd28ade713
children 5f5447b3a082
files addDriToIndexMeta.py manageIndexMetaPURLs.py restService/restService.py restService/searcher.py
diffstat 4 files changed, 57 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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)
                     
--- 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):
         
         
--- 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())
--- /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="""<div class="results"><div class="purls_found_count">%s</div>"""%len(purls)
+        
+        for purl in purls:
+            ret+="""<div class="purls"><a href="%s">%s</a></div>"""%(currentUrl+"/purl/"+purl['purl'],purl['purl'])
+        
+        
+        web.header('Content-Type', 'text/html')
+        return ret+"</div>"
+        
+         
+if __name__ == '__main__':
+    pass
\ No newline at end of file