source: MILK/trunk/milk_server/milk_server/controllers/vocabsearch/vocabsearch.py @ 5201

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/MILK/trunk/milk_server/milk_server/controllers/vocabsearch/vocabsearch.py@5201
Revision 5201, 1.1 KB checked in by cbyrom, 11 years ago (diff)

Add functionality to allow vocab term searches to be done via an
ajax enabled, autocomplete text input. Add new controller and template
packages for this as well as javascript and style sheets. Also update
routing and add (commented out) example of usage in layout + add
documentation on how to use.

Line 
1'''
2 Class representing pylons controller to handle the autocomplete vocab search
3 input box
4 
5 @author: C Byrom, Tessella Apr 2009
6'''
7import logging
8from milk_server.lib.base import *
9
10class VocabsearchController(BaseController):
11
12    def doVocabSearch(self):
13        logging.debug("Running vocabulary search")
14        if not request.params.has_key('query'):
15            logging.error("doSearch invoked without data - something odd is going on - will ignore for now")
16            return
17       
18        query = request.params['query']
19        if not hasattr(g, 'vocabCache'):
20            g.vocabCache = {}
21        elif g.vocabCache.has_key(query):
22            return g.vocabCache[query]
23       
24        records = g.vocabServerClient.searchVocabTerm('http://vocab.ndg.nerc.ac.uk/list/P071/11', 
25                                                      '*%s*' %query)
26        result = ""
27        for record in records:
28            result += record.entryTerm + '\n'
29       
30        # add result to cache, to speed up future searches
31        g.vocabCache[query] = result
32       
33        logging.debug("Returning results:%s" %result)
34        return result
Note: See TracBrowser for help on using the repository browser.