Back to index

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

List of all members.

Public Member Functions

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

Public Attributes

 negated
 use_re
 case
 search_re

Static Public Attributes

int costs = 0

Private Member Functions

def _get_matches
def _build_re
def _get_query_for_search_re

Private Attributes

 _pattern

Static Private Attributes

string _tag = ""

Detailed Description

Base class for all search terms 

Definition at line 34 of file expressions.py.


Constructor & Destructor Documentation

def MoinMoin.search.queryparser.expressions.BaseExpression.__init__ (   self,
  pattern,
  use_re = False,
  case = False 
)
Init a text search

@param pattern: pattern to search for, ascii string or unicode
@param use_re: treat pattern as re of plain text, bool
@param case: do case sensitive search, bool

Reimplemented in MoinMoin.search.queryparser.expressions.DomainSearch, MoinMoin.search.queryparser.expressions.MimetypeSearch, MoinMoin.search.queryparser.expressions.LanguageSearch, and MoinMoin.search.queryparser.expressions.LinkSearch.

Definition at line 43 of file expressions.py.

00043 
00044     def __init__(self, pattern, use_re=False, case=False):
00045         """ Init a text search
00046 
00047         @param pattern: pattern to search for, ascii string or unicode
00048         @param use_re: treat pattern as re of plain text, bool
00049         @param case: do case sensitive search, bool
00050         """
00051         self._pattern = unicode(pattern)
00052         self.negated = 0
00053         self.use_re = use_re
00054         self.case = case
00055 
00056         if use_re:
00057             self._tag += 're:'
00058         if case:
00059             self._tag += 'case:'
00060 
00061         self.pattern, self.search_re = self._build_re(self._pattern, use_re=use_re, case=case)


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 

def MoinMoin.search.queryparser.expressions.BaseExpression._build_re (   self,
  pattern,
  use_re = False,
  case = False,
  stemmed = False 
) [private]
Make a regular expression out of a text pattern 

Definition at line 116 of file expressions.py.

00116 
00117     def _build_re(self, pattern, use_re=False, case=False, stemmed=False):
00118         """ Make a regular expression out of a text pattern """
00119         flags = case and re.U or (re.I | re.U)
00120 
00121         try:
00122             search_re = re.compile(pattern, flags)
00123         except re.error:
00124             pattern = re.escape(pattern)
00125             search_re = re.compile(pattern, flags)
00126 
00127         return pattern, search_re

Here is the caller graph for this function:

def MoinMoin.search.queryparser.expressions.BaseExpression._get_query_for_search_re (   self,
  connection,
  field_to_check = None 
) [private]
Return a query which satisfy self.search_re for field values.
If field_to_check is given check values only for that field.

Definition at line 128 of file expressions.py.

00128 
00129     def _get_query_for_search_re(self, connection, field_to_check=None):
00130         """
00131         Return a query which satisfy self.search_re for field values.
00132         If field_to_check is given check values only for that field.
00133         """
00134         queries = []
00135 
00136         documents = connection.get_all_documents()
00137         for document in documents:
00138             data = document.data
00139             if field_to_check:
00140                 # Check only field with given name
00141                 if field_to_check in data:
00142                     for term in data[field_to_check]:
00143                         if self.search_re.match(term):
00144                             queries.append(connection.query_field(field_to_check, term))
00145             else:
00146                 # Check all fields
00147                 for field, terms in data.iteritems():
00148                     for term in terms:
00149                         if self.search_re.match(term):
00150                             queries.append(connection.query_field(field_to_check, term))
00151 
00152         return Query(OP_OR, queries)

Here is the caller graph for this function:

Return a regular expression of what the term searches for

Used to display the needle in the page.

Reimplemented in MoinMoin.search.queryparser.expressions.CategorySearch, MoinMoin.search.queryparser.expressions.LinkSearch, MoinMoin.search.queryparser.expressions.TextSearch, and MoinMoin.search.queryparser.expressions.AndExpression.

Definition at line 109 of file expressions.py.

00109 
00110     def highlight_re(self):
00111         """ Return a regular expression of what the term searches for
00112 
00113         Used to display the needle in the page.
00114         """
00115         return u''

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

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


Member Data Documentation

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

Definition at line 50 of file expressions.py.

Definition at line 53 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: