whoosh.filedb.filestore.
Storage
¶存储对象的抽象基类。
存储对象是一个虚拟的平面文件系统,允许创建和检索类似文件的对象。( StructFile
对象)。默认实现( FileStorage
)使用目录中的实际文件。
所有对whoosh中文件的访问都会通过这个对象。This allows more different forms of storage (for example, in RAM, in a database, in a single file) to be used transparently.
例如,要创建 FileStorage
对象:
# Create a storage object
st = FileStorage("indexdir")
# Create the directory if it doesn't already exist
st.create()
这个 Storage.create()
方法使交换存储实现变得更加容易。这个 create()
方法处理存储对象的设置。例如, FileStorage.create()
创建目录。数据库实现可能会创建表。这是为了避免在应用程序中放入特定于实现的设置代码。
close
()¶关闭此存储对象打开的所有资源。对于某些存储实现,这将是一个禁止操作,但对于其他存储实现,需要释放锁和/或防止泄漏,因此在完成存储对象操作后最好调用它。
create
()¶创建任何必需的特定于实现的资源。例如,基于文件系统的实现可能创建目录,而数据库实现可能创建表。例如::
from whoosh.filedb.filestore import FileStorage
# Create a storage object
st = FileStorage("indexdir")
# Create any necessary resources
st.create()
此方法返回 self
所以你也可以说:
st = FileStorage("indexdir").create()
应编写存储实现,以便在同一存储上再次调用create()。
返回: | 一 Storage 实例。 |
---|
create_file
(name)¶在此存储中创建具有给定名称的文件。
参数: | name -- 新文件的名称。 |
---|---|
返回: | 一 whoosh.filedb.structfile.StructFile 实例。 |
create_index
(schema, indexname='MAIN', indexclass=None)¶在此存储中创建新索引。
>>> from whoosh import fields
>>> from whoosh.filedb.filestore import FileStorage
>>> schema = fields.Schema(content=fields.TEXT)
>>> # Create the storage directory
>>> st = FileStorage.create("indexdir")
>>> # Create an index in the storage
>>> ix = st.create_index(schema)
参数: |
|
---|---|
返回: | 一 |
delete_file
(name)¶从此存储中删除给定的文件。
参数: | name -- the name to delete. |
---|
destroy
(*args, **kwargs)¶删除与此存储对象相关的任何特定于实现的资源。例如,基于文件系统的实现可能删除目录,数据库实现可能删除表。
这些参数是特定于实现的。
file_modified
(name)¶返回此存储中给定文件的上次修改时间(作为“ctime”unix时间戳)。
参数: | name -- 要检查的名称。 |
---|---|
返回: | “CTIME”号码。 |
index_exists
(indexname=None)¶如果此存储中存在非空索引,则返回true。
参数: | indexname -- 存储对象中索引的名称。可以使用此选项将多个索引存储在同一个存储中。 |
---|---|
返回类型: | bool |
list
()¶返回此存储中的文件名列表。
返回: | 字符串列表 |
---|
lock
(name)¶返回命名锁对象(实现 .acquire()
和 .release()
方法)。不同的存储实现可以使用具有不同保证的不同锁类型。例如,ramstorage对象使用python线程锁,而filestorage对象使用基于文件系统的锁,这些锁在不同的进程中是有效的。
参数: | name -- 锁的名称。 |
---|---|
返回: | 像锁一样的物体。 |
open_file
(name, *args, **kwargs)¶在此存储中打开具有给定名称的文件。
参数: | name -- 新文件的名称。 |
---|---|
返回: | 一 whoosh.filedb.structfile.StructFile 实例。 |
open_index
(indexname='MAIN', schema=None, indexclass=None)¶打开现有索引(创建时使用 create_index()
)在这个仓库里。
>>> from whoosh.filedb.filestore import FileStorage
>>> st = FileStorage("indexdir")
>>> # Open an index in the storage
>>> ix = st.open_index()
参数: |
|
---|---|
返回: | 一 |
optimize
()¶Optimizes the storage object. The meaning and cost of "optimizing" will vary by implementation. For example, a database implementation might run a garbage collection procedure on the underlying database.
rename_file
(frm, to, safe=False)¶重命名此存储中的文件。
参数: |
|
---|
temp_storage
(name=None)¶为临时文件创建新的存储对象。你可以调用 Storage.destroy()
当你用完新的储藏室。
参数: | name -- 新存储的名称。这可能是可选的,也可能是必需的,具体取决于存储实现。 |
---|---|
返回类型: | Storage |
whoosh.filedb.filestore.
FileStorage
(path, supports_mmap=True, readonly=False, debug=False)¶将索引存储为磁盘目录中的文件的存储对象。
在版本3之前,如果目录不存在,初始值设定项将引发IOERROR。从版本3开始,对象不检查初始化时目录是否存在。此更改是为了支持使用 FileStorage.create()
方法。
参数: |
|
---|
whoosh.filedb.filestore.
RamStorage
¶将索引保存在内存中的存储对象。
whoosh.filedb.filestore.
copy_storage
(sourcestore, deststore)¶使用将文件从源存储对象复制到目标存储对象 shutil.copyfileobj
.
whoosh.filedb.filestore.
copy_to_ram
(storage)¶将给定的filestore对象复制到新的ramstorage对象中。
返回类型: | RamStorage |
---|