Changeset 775:29909eb43528 in hatta-dev for hatta.py


Ignore:
Timestamp:
07/09/10 12:47:56 (23 months ago)
Author:
Radomir Dopieralski <sheep@…>
Branch:
default
Message:

fix reindexing of non-existing pages, thanks to Prologic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • hatta.py

    r773 r775  
    14011401    def update_words(self, title, text, cursor): 
    14021402        title_id = self.title_id(title, cursor) 
     1403        cursor.execute('DELETE FROM words WHERE page=?;', (title_id,)) 
     1404        if not text: 
     1405            return 
    14031406        words = self.count_words(self.split_text(text)) 
    14041407        title_words = self.count_words(self.split_text(title)) 
    14051408        for word, count in title_words.iteritems(): 
    14061409            words[word] = words.get(word, 0) + count 
    1407         cursor.execute('DELETE FROM words WHERE page=?;', (title_id,)) 
    14081410        for word, count in words.iteritems(): 
    14091411            cursor.execute('INSERT INTO words VALUES (?, ?, ?);', 
     
    15351537                text = get_text() 
    15361538            except NotFoundErr: 
    1537                 text = u'' 
    1538         extract_links = getattr(page, 'extract_links', lambda x: []) 
    1539         if text: 
    1540             self.update_links(title, extract_links(text), cursor=cursor) 
    1541         self.update_words(title, text, cursor=cursor) 
     1539                text = None 
     1540                title_id = self.title_id(title, cursor) 
     1541                if not list(self.page_backlinks(title)): 
     1542                    cursor.execute("DELETE FROM titles WHERE id=?;", (title_id,)) 
     1543        extract_links = getattr(page, 'extract_links', None) 
     1544        if extract_links and text: 
     1545            links = extract_links(text) 
     1546        else: 
     1547            links = [] 
     1548        self.update_links(title, links, cursor=cursor) 
     1549        self.update_words(title, text or u'', cursor=cursor) 
    15421550 
    15431551    def update_page(self, page, title, data=None, text=None): 
Note: See TracChangeset for help on using the changeset viewer.