view restService/searcher.py @ 24:9ef155b1eec5

description added
author dwinter
date Tue, 12 Mar 2013 14:41:40 +0100
parents cf4503528b5e
children aced422ae66c
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:
                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