1- import re
2-
31from roundup import hyperdb
42
53STOPWORDS = [
108 "THEY" , "THIS" , "TO" , "WAS" , "WILL" , "WITH"
119]
1210
11+
1312def _isLink (propclass ):
1413 return (isinstance (propclass , hyperdb .Link ) or
1514 isinstance (propclass , hyperdb .Multilink ))
1615
16+
1717class Indexer :
1818 def __init__ (self , db ):
1919 self .stopwords = set (STOPWORDS )
@@ -24,7 +24,7 @@ def __init__(self, db):
2424 # than 2 characters
2525 self .minlength = 2
2626 self .maxlength = 50
27- self .language = db .config [('main' ,'indexer_language' )]
27+ self .language = db .config [('main' , 'indexer_language' )]
2828 # Some indexers have a query language. If that is the case,
2929 # we don't parse the user supplied query into a wordlist.
3030 self .query_language = False
@@ -35,7 +35,7 @@ def is_stopword(self, word):
3535 def getHits (self , search_terms , klass ):
3636 return self .find (search_terms )
3737
38- def search (self , search_terms , klass , ignore = {} ):
38+ def search (self , search_terms , klass , ignore = None ):
3939 """Display search results looking for [search, terms] associated
4040 with the hyperdb Class "klass". Ignore hits on {class: property}.
4141 """
@@ -48,16 +48,18 @@ def search(self, search_terms, klass, ignore={}):
4848 for nm , propclass in klass .getprops ().items ():
4949 if _isLink (propclass ):
5050 designator_propname .setdefault (propclass .classname ,
51- []).append (nm )
51+ []).append (nm )
5252
5353 # build a dictionary of nodes and their associated messages
5454 # and files
5555 nodeids = {} # this is the answer
5656 propspec = {} # used to do the klass.find
57- for l in designator_propname .values ():
58- for propname in l :
57+ for pn in designator_propname .values ():
58+ for propname in pn :
5959 propspec [propname ] = {} # used as a set (value doesn't matter)
6060
61+ if ignore is None :
62+ ignore = {}
6163 # don't unpack hits entries as sqlite3's Row can't be unpacked :(
6264 for entry in hits :
6365 # skip this result if we don't care about this class/property
@@ -93,15 +95,16 @@ def search(self, search_terms, klass, ignore={}):
9395 for resid in klass .find (** propspec ):
9496 resid = str (resid )
9597 if resid in nodeids :
96- continue # we ignore duplicate resids
98+ continue # we ignore duplicate resids
9799 nodeids [resid ] = {}
98100 node_dict = nodeids [resid ]
99101 # now figure out where it came from
100102 for linkprop in propspec :
101103 v = klass .get (resid , linkprop )
102104 # the link might be a Link so deal with a single result or None
103105 if isinstance (propdefs [linkprop ], hyperdb .Link ):
104- if v is None : continue
106+ if v is None :
107+ continue
105108 v = [v ]
106109 for nodeid in v :
107110 if nodeid in propspec [linkprop ]:
@@ -112,6 +115,7 @@ def search(self, search_terms, klass, ignore={}):
112115 node_dict [linkprop ].append (nodeid )
113116 return nodeids
114117
118+
115119def get_indexer (config , db ):
116120 indexer_name = getattr (config , "INDEXER" , "" )
117121 if not indexer_name :
@@ -128,7 +132,7 @@ def get_indexer(config, db):
128132 except ImportError :
129133 pass
130134
131- indexer_name = "native" # fallback to native full text search
135+ indexer_name = "native" # fallback to native full text search
132136
133137 if indexer_name == "xapian" :
134138 from .indexer_xapian import Indexer
@@ -140,7 +144,8 @@ def get_indexer(config, db):
140144
141145 if indexer_name == "native-fts" :
142146 if db .dbtype not in ("sqlite" , "postgres" ):
143- raise AssertionError ("Indexer native-fts is configured, but only sqlite and postgres support it. Database is: %r" % db .dbtype )
147+ raise AssertionError ("Indexer native-fts is configured, but only "
148+ "sqlite and postgres support it. Database is: %r" % db .dbtype )
144149
145150 if db .dbtype == "sqlite" :
146151 from roundup .backends .indexer_sqlite_fts import Indexer
@@ -160,5 +165,4 @@ def get_indexer(config, db):
160165 from roundup .backends .indexer_rdbms import Indexer
161166 return Indexer (db )
162167
163- raise AssertionError ("Invalid indexer: %r" % (indexer_name ))
164-
168+ raise AssertionError ("Invalid indexer: %r" % (indexer_name ))
0 commit comments