view restService/searcher.py @ 33:aced422ae66c

added post resquest for search
author dwinter
date Wed, 28 Aug 2013 12:57:36 +0200
parents cf4503528b5e
children
line wrap: on
line source

'''
Created on 02.11.2012

@author: dwinter
'''

import web
import managePurls.manageIndexMetaPURLs as 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 "
        
        
        if hasattr(input, 'q'):
        
            query = input.q
            
            purls=self.md.search(query)
            
            currentUrl = web.ctx.homepath
            
            if purls is None:
                #versuche noch mal mit "/index.meta"
                purls=self.md.search(query+"/index.meta")
                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>"
            
            
    def POST(self):
        data = web.data()
        ret=[]
        print data
        for line in data.split("\n"):
            purls=self.md.search(line)
            
            if purls is None:
                #versuche noch mal mit "/index.meta"
                purls=self.md.search(line+"/index.meta")
                if purls is None:
                    purls=[]    
            

            for purl in purls:
                ret.append("%s\t%s"%(line,purl['purl']))
            
            
        return "\n".join(ret)
         
if __name__ == '__main__':
    pass