Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Attributes
MoinMoin.search.queryparser.expressions.CategorySearch Class Reference
Inheritance diagram for MoinMoin.search.queryparser.expressions.CategorySearch:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.search.queryparser.expressions.CategorySearch:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def highlight_re
def xapian_term
def __str__
def negate
def pageFilter
def search
def xapian_need_postproc
def __unicode__

Public Attributes

 negated
 use_re
 case
 search_re

Static Public Attributes

int costs = 5000

Private Member Functions

def _get_matches

Static Private Attributes

string _tag = 'category:'
string _field_to_search = 'category'

Detailed Description

Search the pages belonging to a category 

Definition at line 496 of file expressions.py.


Member Function Documentation

Definition at line 62 of file expressions.py.

00062 
00063     def __str__(self):
00064         return unicode(self).encode(config.charset, 'replace')

Reimplemented in MoinMoin.search.queryparser.expressions.AndExpression.

Definition at line 156 of file expressions.py.

00156 
00157     def __unicode__(self):
00158         neg = self.negated and '-' or ''
00159         return u'%s%s"%s"' % (neg, self._tag, unicode(self._pattern))
00160 

match categories like this:
    ... some page text ...
    ----
    ## optionally some comments, e.g. about possible categories:
    ## CategoryFoo
    CategoryTheRealAndOnly

    Note: there might be multiple comment lines, but all real categories
  must be on a single line either directly below the ---- or
  directly below some comment lines.

Reimplemented from MoinMoin.search.queryparser.expressions.BaseExpression.

Definition at line 503 of file expressions.py.

00503 
00504     def _get_matches(self, page):
00505         """ match categories like this:
00506             ... some page text ...
00507             ----
00508             ## optionally some comments, e.g. about possible categories:
00509             ## CategoryFoo
00510             CategoryTheRealAndOnly
00511 
00512             Note: there might be multiple comment lines, but all real categories
00513                   must be on a single line either directly below the ---- or
00514                   directly below some comment lines.
00515         """
00516         matches = []
00517 
00518         pattern = r'(?m)(^-----*\s*\r?\n)(^##.*\r?\n)*^(?!##)(.*)\b%s\b' % self.pattern
00519         search_re = self._build_re(pattern, use_re=self.use_re, case=self.case)[1] # we need only a regexp, but not a pattern
00520 
00521         body = page.get_raw_body()
00522         for match in search_re.finditer(body):
00523             matches.append(TextMatch(re_match=match))
00524 
00525         return matches

Here is the call graph for this function:

Return a regular expression of what the term searches for

Used to display the needle in the page.

Reimplemented from MoinMoin.search.queryparser.expressions.BaseExpression.

Definition at line 526 of file expressions.py.

00526 
00527     def highlight_re(self):
00528         return u'(\\b%s\\b)' % self._pattern

Negate the result of this term 

Definition at line 65 of file expressions.py.

00065 
00066     def negate(self):
00067         """ Negate the result of this term """
00068         self.negated = 1

Return a page filtering function

This function is used to filter page list before we search
it. Return a function that get a page name, and return bool.

The default expression does not have any filter function and
return None. Sub class may define custom filter functions.

Reimplemented in MoinMoin.search.queryparser.expressions.TitleSearch, and MoinMoin.search.queryparser.expressions.AndExpression.

Definition at line 69 of file expressions.py.

00069 
00070     def pageFilter(self):
00071         """ Return a page filtering function
00072 
00073         This function is used to filter page list before we search
00074         it. Return a function that get a page name, and return bool.
00075 
00076         The default expression does not have any filter function and
00077         return None. Sub class may define custom filter functions.
00078         """
00079         return None

def MoinMoin.search.queryparser.expressions.BaseExpression.search (   self,
  page 
) [inherited]
Search a page

Returns a list of Match objects or None if term didn't find
anything (vice versa if negate() was called).  Terms containing
other terms must call this method to aggregate the results.
This Base class returns True (Match()) if not negated.

Reimplemented in MoinMoin.search.queryparser.expressions.OrExpression, and MoinMoin.search.queryparser.expressions.AndExpression.

Definition at line 83 of file expressions.py.

00083 
00084     def search(self, page):
00085         """ Search a page
00086 
00087         Returns a list of Match objects or None if term didn't find
00088         anything (vice versa if negate() was called).  Terms containing
00089         other terms must call this method to aggregate the results.
00090         This Base class returns True (Match()) if not negated.
00091         """
00092         logging.debug("%s searching page %r for (negated = %r) %r" % (self.__class__, page.page_name, self.negated, self._pattern))
00093 
00094         matches = self._get_matches(page)
00095 
00096         # Decide what to do with the results.
00097         if self.negated:
00098             if matches:
00099                 result = None
00100             else:
00101                 result = [Match()] # represents "matched" (but as it was a negative match, we have nothing to show)
00102         else: # not negated
00103             if matches:
00104                 result = matches
00105             else:
00106                 result = None
00107         logging.debug("%s returning %r" % (self.__class__, result))
00108         return result

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in MoinMoin.search.queryparser.expressions.AndExpression.

Definition at line 153 of file expressions.py.

00153 
00154     def xapian_need_postproc(self):
00155         return self.case

def MoinMoin.search.queryparser.expressions.CategorySearch.xapian_term (   self,
  request,
  connection 
)

Reimplemented from MoinMoin.search.queryparser.expressions.BaseFieldSearch.

Definition at line 529 of file expressions.py.

00529 
00530     def xapian_term(self, request, connection):
00531         # XXX Probably, it is a good idea to inherit this class from
00532         # BaseFieldSearch and get rid of this definition
00533         if self.use_re:
00534             return self._get_query_for_search_re(connection, 'category')
00535         else:
00536             pattern = self._pattern
00537             # XXX UnicodeQuery was used
00538             return connection.query_field('category', pattern)
00539 

Here is the call graph for this function:


Member Data Documentation

Reimplemented from MoinMoin.search.queryparser.expressions.BaseFieldSearch.

Definition at line 500 of file expressions.py.

string MoinMoin.search.queryparser.expressions.CategorySearch._tag = 'category:' [static, private]

Reimplemented from MoinMoin.search.queryparser.expressions.BaseExpression.

Definition at line 499 of file expressions.py.

Definition at line 53 of file expressions.py.

Reimplemented from MoinMoin.search.queryparser.expressions.BaseExpression.

Definition at line 501 of file expressions.py.

Reimplemented in MoinMoin.search.queryparser.expressions.AndExpression.

Definition at line 51 of file expressions.py.

Reimplemented in MoinMoin.search.queryparser.expressions.BaseTextFieldSearch.

Definition at line 60 of file expressions.py.

Definition at line 52 of file expressions.py.


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