Back to index

moin  1.9.0~rc2
__init__.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - search engine
00004 
00005     @copyright: 2005 MoinMoin:FlorianFesti,
00006                 2005 MoinMoin:NirSoffer,
00007                 2005 MoinMoin:AlexanderSchremmer,
00008                 2006 MoinMoin:ThomasWaldmann,
00009                 2006 MoinMoin:FranzPletz
00010     @license: GNU GPL, see COPYING for details
00011 """
00012 
00013 from MoinMoin import log
00014 logging = log.getLogger(__name__)
00015 
00016 from MoinMoin.search.queryparser import QueryParser, QueryError
00017 from MoinMoin.search.builtin import MoinSearch
00018 
00019 
00020 def searchPages(request, query, sort='weight', mtime=None, historysearch=None, **kw):
00021     """
00022     Search the text of all pages for query.
00023 
00024     @param request: current request
00025     @param query: the expression (string or query objects) we want to search for
00026     @keyword sort: sorting of the search results, either 'weight' or 'page_name'
00027     @keyword mtime: only items modified since mtime
00028     @keyword historysearch: include older revisions of items in search
00029     @keyword titlesearch: treat all terms as title searches (passed to qp)
00030     @keyword case: do case sensitive search (passed to qp)
00031     @keyword regex: treat all terms as regular expression (passed to qp)
00032     @rtype: SearchResults instance
00033     @return: search results
00034     """
00035     return _get_searcher(request, query, sort, mtime, historysearch, **kw).run()
00036 
00037 
00038 def _get_searcher(request, query, sort='weight', mtime=None, historysearch=None, **kw):
00039     """
00040     Return a searcher object according to the configuration.
00041     """
00042     query = _parse_query(query, **kw)
00043     searcher = None
00044 
00045     if request.cfg.xapian_search:
00046         try:
00047             from MoinMoin.search.Xapian.search import XapianSearch, IndexDoesNotExistError
00048             searcher = XapianSearch(request, query, sort, mtime=mtime, historysearch=historysearch)
00049         except ImportError, error:
00050             logging.warning("%s. You should either set xapian_search = False in your wiki config or install/upgrade Xapian." % str(error))
00051         except IndexDoesNotExistError:
00052             logging.warning("Slow moin search is used because the Xapian index does not exist. You should create it using the moin index build command.")
00053 
00054     if searcher is None:
00055         searcher = MoinSearch(request, query, sort, mtime=mtime, historysearch=historysearch)
00056 
00057     return searcher
00058 
00059 def _parse_query(query, **kw):
00060     if isinstance(query, str) or isinstance(query, unicode):
00061         query = QueryParser(**kw).parse_query(query)
00062 
00063     return query
00064