Back to index

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

List of all members.

Public Member Functions

def __init__
def append
def subterms
def costs
def __unicode__
def pageFilter
def sortByCost
def search
def highlight_re
def xapian_need_postproc
def xapian_term
def __str__
def negate

Public Attributes

 negated
 use_re
 case
 search_re

Static Public Attributes

string operator = ' '
int costs = 0

Private Member Functions

def _filter

Private Attributes

 _subterms

Detailed Description

A term connecting several sub terms with a logical AND 

Definition at line 161 of file expressions.py.


Constructor & Destructor Documentation

Definition at line 166 of file expressions.py.

00166 
00167     def __init__(self, *terms):
00168         self._subterms = list(terms)
00169         self.negated = 0


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 from MoinMoin.search.queryparser.expressions.BaseExpression.

Definition at line 181 of file expressions.py.

00181 
00182     def __unicode__(self):
00183         result = ''
00184         for t in self._subterms:
00185             result += self.operator + unicode(t)
00186         return u'[' + result[len(self.operator):] + u']'

def MoinMoin.search.queryparser.expressions.AndExpression._filter (   self,
  terms,
  name 
) [private]
A function that returns True if all terms filter name 

Reimplemented in MoinMoin.search.queryparser.expressions.OrExpression.

Definition at line 187 of file expressions.py.

00187 
00188     def _filter(self, terms, name):
00189         """ A function that returns True if all terms filter name """
00190         result = None
00191         for term in terms:
00192             _filter = term.pageFilter()
00193             t = _filter(name)
00194             if t is True:
00195                 result = True
00196             elif t is False:
00197                 result = False
00198                 break
00199         logging.debug("pageFilter AND returns %r" % result)
00200         return result

Here is the caller graph for this function:

Append another term 

Definition at line 170 of file expressions.py.

00170 
00171     def append(self, expression):
00172         """ Append another term """
00173         self._subterms.append(expression)

Here is the caller graph for this function:

Definition at line 178 of file expressions.py.

00178 
00179     def costs(self):
00180         return sum([t.costs for t in self._subterms])

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 228 of file expressions.py.

00228 
00229     def highlight_re(self):
00230         result = []
00231         for s in self._subterms:
00232             highlight_re = s.highlight_re()
00233             if highlight_re:
00234                 result.append(highlight_re)
00235 
00236         return u'|'.join(result)

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 gets a page name, and return bool, or None.

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

Definition at line 201 of file expressions.py.

00201 
00202     def pageFilter(self):
00203         """ Return a page filtering function
00204 
00205         This function is used to filter page list before we search it.
00206 
00207         Return a function that gets a page name, and return bool, or None.
00208         """
00209         # Sort terms by cost, then get all title searches
00210         self.sortByCost()
00211         terms = [term for term in self._subterms if isinstance(term, TitleSearch)]
00212         if terms:
00213             return lambda name: self._filter(terms, name)

Here is the call graph for this function:

Search for each term, cheap searches first 

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

Reimplemented in MoinMoin.search.queryparser.expressions.OrExpression.

Definition at line 217 of file expressions.py.

00217 
00218     def search(self, page):
00219         """ Search for each term, cheap searches first """
00220         self.sortByCost()
00221         matches = []
00222         for term in self._subterms:
00223             result = term.search(page)
00224             if not result:
00225                 return None
00226             matches.extend(result)
00227         return matches

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 214 of file expressions.py.

00214 
00215     def sortByCost(self):
00216         self._subterms.sort(key=lambda t: t.costs)

Here is the caller graph for this function:

Definition at line 174 of file expressions.py.

00174 
00175     def subterms(self):
00176         return self._subterms

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

Definition at line 237 of file expressions.py.

00237 
00238     def xapian_need_postproc(self):
00239         for term in self._subterms:
00240             if term.xapian_need_postproc():
00241                 return True
00242         return False

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

Reimplemented in MoinMoin.search.queryparser.expressions.OrExpression.

Definition at line 243 of file expressions.py.

00243 
00244     def xapian_term(self, request, connection):
00245         # sort negated terms
00246         terms = []
00247         not_terms = []
00248 
00249         for term in self._subterms:
00250             if not term.negated:
00251                 terms.append(term.xapian_term(request, connection))
00252             else:
00253                 not_terms.append(term.xapian_term(request, connection))
00254 
00255         # prepare query for not negated terms
00256         if terms:
00257             query = Query(OP_AND, terms)
00258         else:
00259             query = Query('') # MatchAll
00260 
00261         # prepare query for negated terms
00262         if not_terms:
00263             query_negated = Query(OP_OR, not_terms)
00264         else:
00265             query_negated = Query()
00266 
00267         return Query(OP_AND_NOT, query, query_negated)
00268 


Member Data Documentation

Definition at line 167 of file expressions.py.

Definition at line 53 of file expressions.py.

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

Definition at line 168 of file expressions.py.

Reimplemented in MoinMoin.search.queryparser.expressions.OrExpression.

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