view MoinMoin/search/Xapian/ @ 29:87a2f219a310

fix pep8 issues
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 28 Feb 2011 01:32:11 +0100
parents 4cd8edde9e94
children 1d8e9b1153d6
line wrap: on
line source
# Copyright: 2005 MoinMoin:FlorianFesti
# Copyright: 2005 MoinMoin:NirSoffer
# Copyright: 2005 MoinMoin:AlexanderSchremmer
# Copyright: 2006-2009 MoinMoin:ThomasWaldmann
# Copyright: 2006 MoinMoin:FranzPletz
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

    MoinMoin - search engine internals

from MoinMoin import log
logging = log.getLogger(__name__)

from MoinMoin.i18n import _, L_, N_
from import BaseSearch, MoinSearch, BaseIndex
from import XapianIndex

class IndexDoesNotExistError(Exception):

class XapianSearch(BaseSearch):

    def __init__(self, request, query, sort='weight', mtime=None, historysearch=0):
        super(XapianSearch, self).__init__(request, query, sort, mtime, historysearch)

        self.index = self._xapian_index()

    def _xapian_index(self):
        """ Get the xapian index if possible

        @param request: current request
        index = XapianIndex(self.request)

        if not index.exists():
            raise IndexDoesNotExistError

        return index

    def _search(self):
        """ Search using Xapian

        Get a list of pages using fast xapian search and
        return moin search in those pages if needed.
        index = self.index

        search_results =, sort=self.sort, historysearch=self.historysearch)
        logging.debug("_xapianSearch: finds: %r" % search_results)

        # Note: .data is (un)pickled inside xappy, so we get back exactly what
        #       we had put into it at indexing time (including unicode objects).
        pages = [{'uid':,
                  'revision':'revision', [0])[0]}
                 for r in search_results]
        if not self.query.xapian_need_postproc():
            # xapian handled the full query

            return self._getHits(pages), (search_results.estimate_is_exact and '' or _('about'), search_results.matches_estimated)

        # some postprocessing by MoinSearch is required
        return MoinSearch(self.request, self.query, self.sort, self.mtime, self.historysearch, pages=pages)._search()