~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/search/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
from MoinMoin import log
14
14
logging = log.getLogger(__name__)
15
15
 
16
 
from MoinMoin.search.queryparser import QueryParser, QueryError
17
 
from MoinMoin.search.builtin import MoinSearch
18
 
 
 
16
from MoinMoin.search.queryparser import QueryParser
 
17
from MoinMoin.search.builtin import Search
19
18
 
20
19
def searchPages(request, query, sort='weight', mtime=None, historysearch=None, **kw):
21
 
    """
22
 
    Search the text of all pages for query.
 
20
    """ Search the text of all pages for query.
23
21
 
24
22
    @param request: current request
25
23
    @param query: the expression (string or query objects) we want to search for
32
30
    @rtype: SearchResults instance
33
31
    @return: search results
34
32
    """
35
 
    return _get_searcher(request, query, sort, mtime, historysearch, **kw).run()
36
 
 
37
 
 
38
 
def _get_searcher(request, query, sort='weight', mtime=None, historysearch=None, **kw):
39
 
    """
40
 
    Return a searcher object according to the configuration.
41
 
    """
42
 
    query = _parse_query(query, **kw)
43
 
    searcher = None
44
 
 
45
 
    if request.cfg.xapian_search:
46
 
        try:
47
 
            from MoinMoin.search.Xapian.search import XapianSearch, IndexDoesNotExistError
48
 
            searcher = XapianSearch(request, query, sort, mtime=mtime, historysearch=historysearch)
49
 
        except ImportError, error:
50
 
            logging.warning("%s. You should either set xapian_search = False in your wiki config or install/upgrade Xapian." % str(error))
51
 
        except IndexDoesNotExistError:
52
 
            logging.warning("Slow moin search is used because the Xapian index does not exist. You should create it using the moin index build command.")
53
 
 
54
 
    if searcher is None:
55
 
        searcher = MoinSearch(request, query, sort, mtime=mtime, historysearch=historysearch)
56
 
 
57
 
    return searcher
58
 
 
59
 
def _parse_query(query, **kw):
60
33
    if isinstance(query, str) or isinstance(query, unicode):
61
34
        query = QueryParser(**kw).parse_query(query)
62
 
 
63
 
    return query
 
35
    return Search(request, query, sort, mtime=mtime,
 
36
            historysearch=historysearch).run()
64
37