# HG changeset patch # User Jeff Hammel # Date 1606252613 28800 # Node ID 87990e313a91e6a246056632ecc99a99c0370f77 # Parent cabe9753505775b374f36ce56e5b8fcce15a8513 py3 diff -r cabe97535057 -r 87990e313a91 toolbox/search.py --- a/toolbox/search.py Tue Nov 24 13:15:33 2020 -0800 +++ b/toolbox/search.py Tue Nov 24 13:16:53 2020 -0800 @@ -54,7 +54,7 @@ self.keywords.add(key) if not isinstance(kw[key], str): kw[key] = ' '.join(kw[key]) - kw[key] = unicode(kw[key]) + kw[key] = str(kw[key]) writer.update_document(name=name, description=description, **kw) writer.commit() @@ -62,39 +62,25 @@ def delete(self, name): """delete a document of a given name""" writer = self.ix.writer() - name = unicode(name) writer.delete_by_term('name', name) writer.commit() def __call__(self, query): """search""" - query = unicode(query) query_parser = QueryParser("description", schema=self.ix.schema) myquery = query_parser.parse(query) -# Old code: too strict -# extendedquery = Or([myquery] + -# [Term(field, query) for field in self.keywords]) - # New code: too permissive -# extendedquery = [myquery] excluded = set(['AND', 'OR', 'NOT']) terms = [i for i in query.split() if i not in excluded] -# for field in self.keywords: -# extendedquery.extend([Term(field, term) for term in terms]) -# extendedquery = Or(extendedquery) - - # Code should look something like - #Or([myquery] + [Or( - # extendedquery = [myquery] extendedquery = And([Or([myquery] + [Term('description', term), Term('name', term)] + [Term(field, term) for field in self.keywords]) for term in terms]) # perform the search searcher = self.ix.searcher() return [i['name'] for i in searcher.search(extendedquery, limit=None)] - + def __del__(self): if self.tempdir: # delete the temporary directory, if present