plugin_h_search / plugin_h_search /

Filename Size Date modified Message
1.1 KB
1.7 KB
13.2 KB
Search plugin for web2py (alpha)

Author  : Hans Christian von Stockhausen <hc at>
Date    : 2011-01-13
Home    :
License : MIT (see LICENSE)

This module implements a simple search engine for web2py-powered sites. It is 
intended for local site search on or off Google Appengine. Results are ranked 
by keyword frequency, keyword position relative to the top of the page and 
keyword proximity to one another. 
The engine is based on "Programming Collective Intelligence" (Ch. 4).


This module requires the following third party modules:

pyporter2     -
BeautifulSoup -

Note: The w2p plugin package contains these already for your convinience.


### models/
search = local_import('plugin_h_search')

### controllers/
search = local_import('plugin_h_search')

@search.index(globals(), search.INDEX_DAILY)
def foo():
    " The entire html output of this page is indexed max once a day "
    return dict(message='Hello World')

def bar():
    " Index arbitrary data. Note that no decorator is used "
    url = ''
    data = urllib2.urlopen(url).read()
    idx = search.Indexer(globals(), search.INDEX_WEEKLY)
    idx.add(data, url)
    return 'Indexed %s' % url

@cache(request.vars.get('q'), time_expire=3600, cache_model=cache_disk)  
def search():
    return dict(, request.vars.get('q'))
### views/mycontroller/search.html
{{extend 'layout.html'}}
{{for r in results:}}
    {{=A(XML(r.title), _href=r.url)}}