11#$Id: indexer_rdbms.py,v 1.18 2008-09-01 00:43:02 richard Exp $
2- ''' This implements the full-text indexer over two RDBMS tables. The first
2+ """ This implements the full-text indexer over two RDBMS tables. The first
33is a mapping of words to occurance IDs. The second maps the IDs to (Class,
44propname, itemid) instances.
5- '''
6- import re , sets
5+ """
6+ import re
7+ # Python 2.3 ... 2.6 compatibility:
8+ from roundup .anypy .sets_ import set
79
810from roundup .backends .indexer_common import Indexer as IndexerBase
911
@@ -14,27 +16,27 @@ def __init__(self, db):
1416 self .reindex = 0
1517
1618 def close (self ):
17- ''' close the indexing database'''
19+ """ close the indexing database"""
1820 # just nuke the circular reference
1921 self .db = None
2022
2123 def save_index (self ):
22- ''' Save the changes to the index.'''
24+ """ Save the changes to the index."""
2325 # not necessary - the RDBMS connection will handle this for us
2426 pass
2527
2628 def force_reindex (self ):
27- ''' Force a reindexing of the database. This essentially
29+ """ Force a reindexing of the database. This essentially
2830 empties the tables ids and index and sets a flag so
29- that the databases are reindexed'''
31+ that the databases are reindexed"""
3032 self .reindex = 1
3133
3234 def should_reindex (self ):
33- ''' returns True if the indexes need to be rebuilt'''
35+ """ returns True if the indexes need to be rebuilt"""
3436 return self .reindex
3537
3638 def add_text (self , identifier , text , mime_type = 'text/plain' ):
37- ''' "identifier" is (classname, itemid, property) '''
39+ """ "identifier" is (classname, itemid, property) """
3840 if mime_type != 'text/plain' :
3941 return
4042
@@ -65,7 +67,7 @@ def add_text(self, identifier, text, mime_type='text/plain'):
6567 text = unicode (text , "utf-8" , "replace" ).upper ()
6668 wordlist = [w .encode ("utf-8" , "replace" )
6769 for w in re .findall (r'(?u)\b\w{2,25}\b' , text )]
68- words = sets . Set ()
70+ words = set ()
6971 for word in wordlist :
7072 if self .is_stopword (word ): continue
7173 if len (word ) > 25 : continue
@@ -77,10 +79,10 @@ def add_text(self, identifier, text, mime_type='text/plain'):
7779 self .db .cursor .executemany (sql , words )
7880
7981 def find (self , wordlist ):
80- ''' look up all the words in the wordlist.
82+ """ look up all the words in the wordlist.
8183 If none are found return an empty dictionary
8284 * more rules here
83- '''
85+ """
8486 if not wordlist :
8587 return []
8688
0 commit comments