Back to index

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

List of all members.

Public Member Functions

def __init__
def weight
def add_matches
def get_matches

Public Attributes

 page_name
 attachment
 page
 rev

Private Member Functions

def _unique_matches

Private Attributes

 _matches

Detailed Description

Represents a page in a search result 

Definition at line 96 of file results.py.


Constructor & Destructor Documentation

def MoinMoin.search.results.FoundPage.__init__ (   self,
  page_name,
  matches = None,
  page = None,
  rev = 0 
)

Definition at line 99 of file results.py.

00099 
00100     def __init__(self, page_name, matches=None, page=None, rev=0):
00101         self.page_name = page_name
00102         self.attachment = '' # this is not an attachment
00103         self.page = page
00104         self.rev = rev
00105         if matches is None:
00106             matches = []
00107         self._matches = matches


Member Function Documentation

def MoinMoin.search.results.FoundPage._unique_matches (   self,
  type = Match 
) [private]
Get a list of unique matches of type

The result is sorted by match.start, because its easy to remove
duplicates like this.

@param type: type of match to return
@rtype: list
@return: list of matches of type, sorted by match.start

Reimplemented in MoinMoin.search.results.FoundRemote.

Definition at line 159 of file results.py.

00159 
00160     def _unique_matches(self, type=Match):
00161         """ Get a list of unique matches of type
00162 
00163         The result is sorted by match.start, because its easy to remove
00164         duplicates like this.
00165 
00166         @param type: type of match to return
00167         @rtype: list
00168         @return: list of matches of type, sorted by match.start
00169         """
00170         # Filter by type and sort by match.start using fast schwartzian transform.
00171         tmp = [(match.start, match) for match in self._matches if isinstance(match, type)]
00172         tmp.sort()
00173 
00174         if not len(tmp):
00175             return []
00176 
00177         # Get first match into matches list
00178         matches = [tmp[0][1]]
00179 
00180         # Add the remaining ones of matches ignoring identical matches
00181         for item in tmp[1:]:
00182             if item[1] == matches[-1]:
00183                 continue
00184             matches.append(item[1])
00185 
00186         return matches
00187 

Here is the caller graph for this function:

def MoinMoin.search.results.FoundPage.add_matches (   self,
  matches 
)
Add found matches 

Definition at line 126 of file results.py.

00126 
00127     def add_matches(self, matches):
00128         """ Add found matches """
00129         self._matches.extend(matches)

def MoinMoin.search.results.FoundPage.get_matches (   self,
  unique = 1,
  sort = 'start',
  type = Match 
)
Return all matches of type sorted by sort

@param unique: return only unique matches (bool)
@param sort: match attribute to sort by (string)
@param type: type of match to return (Match or sub class)
@rtype: list
@return: list of matches

Reimplemented in MoinMoin.search.results.FoundRemote.

Definition at line 130 of file results.py.

00130 
00131     def get_matches(self, unique=1, sort='start', type=Match):
00132         """ Return all matches of type sorted by sort
00133 
00134         @param unique: return only unique matches (bool)
00135         @param sort: match attribute to sort by (string)
00136         @param type: type of match to return (Match or sub class)
00137         @rtype: list
00138         @return: list of matches
00139         """
00140         if unique:
00141             matches = self._unique_matches(type=type)
00142             if sort == 'start':
00143                 # matches already sorted by match.start, finished.
00144                 return matches
00145         else:
00146             matches = self._matches
00147 
00148         # Filter by type and sort by sort using fast schwartzian transform.
00149         if sort == 'start':
00150             tmp = [(match.start, match) for match in matches if isinstance(match, type)]
00151         else:
00152             tmp = [(match.weight(), match) for match in matches if isinstance(match, type)]
00153         tmp.sort()
00154         if sort == 'weight':
00155             tmp.reverse()
00156         matches = [item[1] for item in tmp]
00157 
00158         return matches

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.search.results.FoundPage.weight (   self,
  unique = 1 
)
returns how important this page is for the terms searched for

Summarize the weight of all page matches

@param unique: ignore identical matches
@rtype: int
@return: page weight

Reimplemented in MoinMoin.search.results.FoundRemote, and MoinMoin.search.results.FoundAttachment.

Definition at line 108 of file results.py.

00108 
00109     def weight(self, unique=1):
00110         """ returns how important this page is for the terms searched for
00111 
00112         Summarize the weight of all page matches
00113 
00114         @param unique: ignore identical matches
00115         @rtype: int
00116         @return: page weight
00117         """
00118         weight = 0
00119         for match in self.get_matches(unique=unique):
00120             weight += match.weight()
00121             # More sophisticated things to be added, like increase
00122             # weight of near matches.
00123         if self.page.parse_processing_instructions().get('deprecated', False):
00124             weight = int(weight / 4) # rank it down
00125         return weight

Here is the call graph for this function:


Member Data Documentation


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