index
模块¶
包含用于创建、维护和使用索引的主要函数/类。
功能¶
-
whoosh.index.
create_in
(dirname, schema, indexname=None)¶ 在目录中创建索引的便利函数。负责为您创建文件存储对象。
- 参数
dirname -- 要在其中创建索引的目录的路径字符串。
schema -- 一
whoosh.fields.Schema
描述索引字段的对象。indexname -- the name of the index to create; you only need to specify this if you are creating multiple indexes within the same storage object.
- 返回
-
whoosh.index.
open_dir
(dirname, indexname=None, readonly=False, schema=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. index name是要创建的索引的名称;如果在同一存储对象中有多个索引,则只需指定此名称。
- 参数
dirname -- 要在其中创建索引的目录的路径字符串。
indexname -- 要创建的索引的名称;只有在同一存储对象中有多个索引时,才需要指定此名称。
-
whoosh.index.
exists_in
(dirname, indexname=None)¶ 如果dirname包含whoosh索引,则返回true。
- 参数
dirname -- 目录的文件路径。
indexname -- 索引的名称。如果没有,则使用默认索引名称。
-
whoosh.index.
exists
(storage, indexname=None)¶ 弃用;使用
storage.index_exists()
.- 参数
storage -- 一个store.storage对象。
indexname -- 索引的名称。如果没有,则使用默认索引名称。
-
whoosh.index.
version_in
(dirname, indexname=None)¶ Returns a tuple of (release_version, format_version), where release_version is the release version number of the Whoosh code that created the index -- e.g. (0, 1, 24) -- and format_version is the version number of the on-disk format used for the index -- e.g. -102.
您应该避免将重要性附加到第二个数字(索引版本)。这只是TOC文件的版本号,可能不应该在公共接口中公开。检查当前版本的whoosh是否可以打开索引的最佳方法是实际尝试打开它并查看它是否引发了
whoosh.index.IndexVersionError
例外。请注意,版本和格式版本作为index.release和index.version中index对象的属性提供。
- 参数
dirname -- 包含索引的目录的文件路径。
indexname -- 索引的名称。如果没有,则使用默认索引名称。
- 返回
(主要版本、次要版本、构建版本)、格式版本)
-
whoosh.index.
version
(storage, indexname=None)¶ Returns a tuple of (release_version, format_version), where release_version is the release version number of the Whoosh code that created the index -- e.g. (0, 1, 24) -- and format_version is the version number of the on-disk format used for the index -- e.g. -102.
您应该避免将重要性附加到第二个数字(索引版本)。这只是TOC文件的版本号,可能不应该在公共接口中公开。检查当前版本的whoosh是否可以打开索引的最佳方法是实际尝试打开它并查看它是否引发了
whoosh.index.IndexVersionError
例外。请注意,版本和格式版本作为index.release和index.version中index对象的属性提供。
- 参数
storage -- 一个store.storage对象。
indexname -- 索引的名称。如果没有,则使用默认索引名称。
- 返回
(主要版本、次要版本、构建版本)、格式版本)
基类¶
-
class
whoosh.index.
Index
¶ 表示文档的索引集合。
-
add_field
(fieldname, fieldspec)¶ 将字段添加到索引的架构中。
- 参数
fieldname -- 要添加的字段的名称。
fieldspec -- 实例化
whoosh.fields.FieldType
对象。
-
close
()¶ 关闭索引对象本身持有的所有打开的资源。这可能不会关闭所有在任何地方使用的资源,例如搜索者对象。
-
doc_count
()¶ 返回此索引中未删除的文档总数。
-
doc_count_all
()¶ 返回此索引中已删除或未删除的文档总数。
-
field_length
(fieldname)¶ 返回所有文档中字段的总长度。
-
is_empty
()¶ 如果此索引为空,则返回true(即,它从未成功写入过任何文档)。
-
last_modified
()¶ 返回索引的上次修改时间,如果后端不支持上次修改时间,则返回-1。
-
latest_generation
()¶ 返回此索引的最新一代的生成号,如果后端不支持版本控制,则返回-1。
-
max_field_length
(fieldname)¶ 返回所有文档中字段的最大长度。
-
optimize
()¶ 如有必要,优化此索引。
-
reader
(reuse=None)¶ 返回此索引的IndexReader对象。
- 参数
reuse -- 现有的读卡器。某些实现可能会从现有的读卡器回收资源以创建新的读卡器。请注意,“回收”读卡器中新读卡器未使用的任何资源都将被关闭,因此之后您不能使用它。
- 返回类型
-
remove_field
(fieldname)¶ 从索引架构中删除命名字段。根据后端实现的不同,这可能会或可能不会从索引中实际删除字段的现有数据。优化索引应始终清除已删除字段的现有数据。
-
searcher
(**kwargs)¶ 返回此索引的搜索者对象。关键字参数将传递给搜索者对象的构造函数。
-
up_to_date
()¶ 如果此对象表示此索引的最新一代,则返回true。如果此对象不是最新版本(即,在打开此对象后,其他人已更新了索引),则返回false。
-
writer
(**kwargs)¶ 返回此索引的IndexWriter对象。
-
例外情况¶
-
exception
whoosh.index.
LockError
¶
-
exception
whoosh.index.
IndexError
¶ 一般索引错误。
-
exception
whoosh.index.
IndexVersionError
(msg, version, release=None)¶ 尝试使用当前版本的whoosh无法读取的格式打开索引时引发。也就是说,当您试图打开的索引与这个版本的whoosh不向后或向前兼容时。
-
exception
whoosh.index.
OutOfDateError
¶ 尝试将更改提交到非最新版本的索引时引发。
-
exception
whoosh.index.
EmptyIndexError
¶ 尝试使用没有索引项的索引时引发。