Changeset 749:53688022b592 in hatta-dev


Ignore:
Timestamp:
01/24/10 16:11:12 (2 years ago)
Author:
sheep@…
Branch:
default
Message:

add plain_text method to text pages, for extracting text for indexing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • hatta.py

    r748 r749  
    14751475        """Updates the content of the database, needs locks around.""" 
    14761476 
    1477         mime = page_mime(title) 
    1478         if not mime.startswith('text/'): 
    1479             self.update_words(title, '', cursor=cursor) 
    1480             return 
    14811477        if text is None: 
     1478            get_text = getattr(page, 'plain_text', lambda: u'') 
    14821479            try: 
    1483                 text = self.storage.page_text(title) 
     1480                text = get_text() 
    14841481            except werkzeug.exceptions.NotFound: 
    14851482                text = u'' 
    1486         extract_links = getattr(page, 'extract_links', None) 
    1487         if extract_links is not None: 
    1488             links = extract_links(text) 
    1489             self.update_links(title, links, cursor=cursor) 
     1483        extract_links = getattr(page, 'extract_links', lambda: []) 
     1484        if text: 
     1485            self.update_links(title, extract_links(text), cursor=cursor) 
    14901486        self.update_words(title, text, cursor=cursor) 
    14911487 
     
    19491945            yield werkzeug.html(line) 
    19501946        yield '</pre>' 
     1947 
     1948    def plain_text(self): 
     1949        """ 
     1950        Get the content of the page with all markup removed, used for 
     1951        indexing. 
     1952        """ 
     1953 
     1954        return self.storage.page_text(self.title) 
     1955 
    19511956 
    19521957    def view_content(self, lines=None): 
Note: See TracChangeset for help on using the changeset viewer.