Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions
MoinMoin.search.builtin.BaseSearch Class Reference
Inheritance diagram for MoinMoin.search.builtin.BaseSearch:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def run

Public Attributes

 request
 query
 sort
 mtime
 historysearch
 filtered
 fs_rootpage

Private Member Functions

def _search
def _filter
def _get_search_results
def _get_match
def _getHits

Detailed Description

A search run 

Definition at line 239 of file builtin.py.


Constructor & Destructor Documentation

def MoinMoin.search.builtin.BaseSearch.__init__ (   self,
  request,
  query,
  sort = 'weight',
  mtime = None,
  historysearch = 0 
)
@param request: current request
@param query: search query objects tree
@keyword sort: the sorting of the results (default: 'weight')
@keyword mtime: only show items newer than this timestamp (default: None)
@keyword historysearch: whether to show old revisions of a page (default: 0)

Reimplemented in MoinMoin.search.Xapian.search.XapianSearch.

Definition at line 242 of file builtin.py.

00242 
00243     def __init__(self, request, query, sort='weight', mtime=None, historysearch=0):
00244         """
00245         @param request: current request
00246         @param query: search query objects tree
00247         @keyword sort: the sorting of the results (default: 'weight')
00248         @keyword mtime: only show items newer than this timestamp (default: None)
00249         @keyword historysearch: whether to show old revisions of a page (default: 0)
00250         """
00251         self.request = request
00252         self.query = query
00253         self.sort = sort
00254         self.mtime = mtime
00255         self.historysearch = historysearch
00256         self.filtered = False
00257         self.fs_rootpage = "FS" # XXX FS hardcoded


Member Function Documentation

def MoinMoin.search.builtin.BaseSearch._filter (   self,
  hits 
) [private]
Filter out deleted or acl protected pages

@param hits: list of hits

Definition at line 283 of file builtin.py.

00283 
00284     def _filter(self, hits):
00285         """
00286         Filter out deleted or acl protected pages
00287 
00288         @param hits: list of hits
00289         """
00290         userMayRead = self.request.user.may.read
00291         fs_rootpage = self.fs_rootpage + "/"
00292         thiswiki = (self.request.cfg.interwikiname, 'Self')
00293         filtered = [(wikiname, page, attachment, match, rev)
00294                 for wikiname, page, attachment, match, rev in hits
00295                     if (not wikiname in thiswiki or
00296                        page.exists() and userMayRead(page.page_name) or
00297                        page.page_name.startswith(fs_rootpage)) and
00298                        (not self.mtime or self.mtime <= page.mtime_usecs()/1000000)]
00299         return filtered

Here is the caller graph for this function:

def MoinMoin.search.builtin.BaseSearch._get_match (   self,
  page = None,
  uid = None 
) [private]
Get all matches

@param page: the current page instance

Definition at line 303 of file builtin.py.

00303 
00304     def _get_match(self, page=None, uid=None):
00305         """
00306         Get all matches
00307 
00308         @param page: the current page instance
00309         """
00310         if page:
00311             return self.query.search(page)

Here is the caller graph for this function:

def MoinMoin.search.builtin.BaseSearch._get_search_results (   self,
  hits,
  start,
  estimated_hits 
) [private]

Definition at line 300 of file builtin.py.

00300 
00301     def _get_search_results(self, hits, start, estimated_hits):
00302         return getSearchResults(self.request, self.query, hits, start, self.sort, estimated_hits)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.search.builtin.BaseSearch._getHits (   self,
  pages 
) [private]
Get the hit tuples in pages through _get_match 

Definition at line 312 of file builtin.py.

00312 
00313     def _getHits(self, pages):
00314         """ Get the hit tuples in pages through _get_match """
00315         logging.debug("_getHits searching in %d pages ..." % len(pages))
00316         hits = []
00317         revisionCache = {}
00318         fs_rootpage = self.fs_rootpage
00319         for hit in pages:
00320 
00321             uid = hit.get('uid')
00322             wikiname = hit['wikiname']
00323             pagename = hit['pagename']
00324             attachment = hit['attachment']
00325             revision = int(hit.get('revision', 0))
00326 
00327             logging.debug("_getHits processing %r %r %d %r" % (wikiname, pagename, revision, attachment))
00328 
00329             if wikiname in (self.request.cfg.interwikiname, 'Self'): # THIS wiki
00330                 page = Page(self.request, pagename, rev=revision)
00331 
00332                 if not self.historysearch and revision:
00333                     revlist = page.getRevList()
00334                     # revlist can be empty if page was nuked/renamed since it was included in xapian index
00335                     if not revlist or revlist[0] != revision:
00336                         # nothing there at all or not the current revision
00337                         logging.debug("no history search, skipping non-current revision...")
00338                         continue
00339 
00340                 if attachment:
00341                     # revision currently is 0 ever
00342                     if pagename == fs_rootpage: # not really an attachment
00343                         page = Page(self.request, "%s/%s" % (fs_rootpage, attachment))
00344                         hits.append((wikiname, page, None, None, revision))
00345                     else:
00346                         matches = self._get_match(page=None, uid=uid)
00347                         hits.append((wikiname, page, attachment, matches, revision))
00348                 else:
00349                     matches = self._get_match(page=page, uid=uid)
00350                     logging.debug("self._get_match %r" % matches)
00351                     if matches:
00352                         if not self.historysearch and pagename in revisionCache and revisionCache[pagename][0] < revision:
00353                             hits.remove(revisionCache[pagename][1])
00354                             del revisionCache[pagename]
00355                         hits.append((wikiname, page, attachment, matches, revision))
00356                         revisionCache[pagename] = (revision, hits[-1])
00357 
00358             else: # other wiki
00359                 hits.append((wikiname, pagename, attachment, None, revision))
00360         logging.debug("_getHits returning %r." % hits)
00361         return hits
00362 

Here is the call graph for this function:

Here is the caller graph for this function:

Search pages.

Return list of tuples (wikiname, page object, attachment,
matches, revision) and estimated number of search results (if
there is no estimate, None should be returned).

The list may contain deleted pages or pages the user may not read.

Reimplemented in MoinMoin.search.builtin.MoinSearch, and MoinMoin.search.Xapian.search.XapianSearch.

Definition at line 271 of file builtin.py.

00271 
00272     def _search(self):
00273         """
00274         Search pages.
00275 
00276         Return list of tuples (wikiname, page object, attachment,
00277         matches, revision) and estimated number of search results (if
00278         there is no estimate, None should be returned).
00279 
00280         The list may contain deleted pages or pages the user may not read.
00281         """
00282         raise NotImplementedError()

Here is the caller graph for this function:

Perform search and return results object 

Definition at line 258 of file builtin.py.

00258 
00259     def run(self):
00260         """ Perform search and return results object """
00261 
00262         start = time.time()
00263         hits, estimated_hits = self._search()
00264 
00265         # important - filter deleted pages or pages the user may not read!
00266         if not self.filtered:
00267             hits = self._filter(hits)
00268             logging.debug("after filtering: %d hits" % len(hits))
00269 
00270         return self._get_search_results(hits, start, estimated_hits)

Here is the call graph for this function:


Member Data Documentation

Reimplemented in MoinMoin.search.builtin.MoinSearch.

Definition at line 255 of file builtin.py.

Definition at line 256 of file builtin.py.

Definition at line 254 of file builtin.py.

Definition at line 253 of file builtin.py.

Definition at line 251 of file builtin.py.

Definition at line 250 of file builtin.py.

Definition at line 252 of file builtin.py.


The documentation for this class was generated from the following file: