changeset 18:87990e313a91

py3
author Jeff Hammel <k0scist@gmail.com>
date Tue, 24 Nov 2020 13:16:53 -0800
parents cabe97535057
children c6800e0b01ed
files toolbox/search.py
diffstat 1 files changed, 2 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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