index 5b5dd60c69f15fe3b15f0885aadcc2bea99b7d62..b34261261a3f48eb74e826bd52a0c0136913d353 100644 (file)
self.stopwords = set(STOPWORDS)
for word in db.config[('main', 'indexer_stopwords')]:
self.stopwords.add(word)
+ # Do not index anything longer than 25 characters since that'll be
+ # gibberish (encoded text or somesuch) or shorter than 2 characters
+ self.minlength = 2
+ self.maxlength = 25
def is_stopword(self, word):
return word in self.stopwords
def search(self, search_terms, klass, ignore={}):
"""Display search results looking for [search, terms] associated
with the hyperdb Class "klass". Ignore hits on {class: property}.
-
- "dre" is a helper, not an argument.
"""
# do the index lookup
hits = self.getHits(search_terms, klass)
return {}
designator_propname = {}
- for nm, propclass in klass.getprops().items():
+ for nm, propclass in klass.getprops().iteritems():
if _isLink(propclass):
designator_propname.setdefault(propclass.classname,
[]).append(nm)
# and files
nodeids = {} # this is the answer
propspec = {} # used to do the klass.find
- for l in designator_propname.values():
+ for l in designator_propname.itervalues():
for propname in l:
propspec[propname] = {} # used as a set (value doesn't matter)
# skip this result if we don't care about this class/property
classname = entry[0]
property = entry[2]
- if ignore.has_key((classname, property)):
+ if (classname, property) in ignore:
continue
# if it's a property on klass, it's easy
# backends as that can cause problems down the track)
nodeid = str(entry[1])
if classname == klass.classname:
- if not nodeids.has_key(nodeid):
+ if nodeid not in nodeids:
nodeids[nodeid] = {}
continue
# make sure the class is a linked one, otherwise ignore
- if not designator_propname.has_key(classname):
+ if classname not in designator_propname:
continue
# it's a linked class - set up to do the klass.find
propspec[linkprop][nodeid] = 1
# retain only the meaningful entries
- for propname, idset in propspec.items():
+ for propname, idset in list(propspec.items()):
if not idset:
del propspec[propname]
nodeids[resid] = {}
node_dict = nodeids[resid]
# now figure out where it came from
- for linkprop in propspec.keys():
+ for linkprop in propspec:
v = klass.get(resid, linkprop)
# the link might be a Link so deal with a single result or None
if isinstance(propdefs[linkprop], hyperdb.Link):
if v is None: continue
v = [v]
for nodeid in v:
- if propspec[linkprop].has_key(nodeid):
+ if nodeid in propspec[linkprop]:
# OK, this node[propname] has a winner
- if not node_dict.has_key(linkprop):
+ if linkprop not in node_dict:
node_dict[linkprop] = [nodeid]
else:
node_dict[linkprop].append(nodeid)