def __init__(self, *args, **kwargs): self.default = kwargs.pop("default", None) self.parser = None self.fields = kwargs.pop('fields', []) + ['id'] self.real_time = kwargs.pop('real_time', True) if not os.path.lexists(STORAGE_DIR): os.makedirs(STORAGE_DIR) self.storage = store.FileStorage(STORAGE_DIR) try: self.index = Index(self.storage) except (IndexError, EmptyIndexError): self.index = None super(WhooshManager, self).__init__(*args, **kwargs)
def open_dir(dirname, indexname=None): """Convenience function for opening an index in a directory. Takes care of creating a FileStorage object for you. dirname is the filename of the directory in containing the index. indexname is the name of the index to create; you only need to specify this if you have multiple indexes within the same storage object. Returns an Index object. """ if indexname is None: indexname = _DEF_INDEX_NAME return Index(store.FileStorage(dirname), indexname=indexname)
def create_in(dirname, schema=None, indexname=None, **kwargs): """Convenience function to create an index in a directory. Takes care of creating a FileStorage object for you. dirname is the filename of the directory in which to create the index. schema is a fields.Schema object describing the index's fields. indexname is the name of the index to create; you only need to specify this if you are creating multiple indexes within the same storage object. If you specify both a schema and keyword arguments, the schema wins. Returns an Index object. """ if not indexname: indexname = _DEF_INDEX_NAME storage = store.FileStorage(dirname) if kwargs and not schema: schema = fields.Schema(**kwargs) elif not schema and not kwargs: raise Exception( "You must specify either a schema or keyword arguments.") return Index(storage, schema=schema, indexname=indexname, create=True)
def make_index(self, dirname, schema): if not exists(dirname): mkdir(dirname) st = store.FileStorage(dirname) ix = index.Index(st, schema, create=True) return ix