ElasticSearch/Lucene程序员

Apache Lucene - Index File Forma

2018-05-10  本文已影响21人  囧雪啥都不知道

Apache Lucene - Index File Formats(索引文件格式)


Introduction(引言)

This document defines the index file formats used in this version of Lucene. If you are using a different version of Lucene, please consult the copy of docs/ that was distributed with the version you are using.

本文档定义了V7.0.0版本Lucene中使用的索引文件格式。如果您使用的是不同版本的Lucene,请查阅docs/随您使用的版本一起发布的副本。

This document attempts to provide a high-level definition of the Apache Lucene file formats.

本文档尝试提供对Apache Lucene文件格式的高级定义。

Definitions(定义)

The fundamental concepts in Lucene are index, document, field and term.

Lucene的基本概念包括索引(index),文档(document),域(field)和词(term)。

An index contains a sequence of documents.

索引包含一系列文档。

The same sequence of bytes in two different fields is considered a different term. Thus terms are represented as a pair: the string naming the field, and the bytes within the field.

两个不同域(field)中的相同字节(byte)序列被认为是不同的词(term)。因此,词由一对(要素)表示:域(field)名、域(field)内字节组(bytes)。

Inverted Indexing(倒排索引)

The index stores statistics about terms in order to make term-based search more efficient. Lucene's index falls into the family of indexes known as an inverted index. This is because it can list, for a term, the documents that contain it. This is the inverse of the natural relationship, in which documents list terms.

(倒排索引即)存储与词(term)相关的统计信息的索引(index),其目的是提高基于词(term based)的搜索效率。Lucene的索引(index)属于倒排索引的索引族。(叫做倒排索引)是因为对于一个词(term),此索引(index)可以存储包含此词(term)的文档列表(document list)。这与某个文件(document)存储一些词列表(term list)的自然顺序相反。

Types of Fields(域(field)的类型)

In Lucene, fields may be stored, in which case their text is stored in the index literally, in a non-inverted manner. Fields that are inverted are called indexed. A field may be both stored and indexed.

在Lucene中,域(field)可以被存储(store),此时,域(field)内的文本(text)会依照原样,以非倒转(non-inverted)的方式存入索引中。被倒转(inverted)的域(field)称作被索引的(indexed)。一个域可以同时被存储(store)和索引(index)。

The text of a field may be tokenized into terms to be indexed, or the text of a field may be used literally as a term to be indexed. Most fields are tokenized, but sometimes it is useful for certain identifier fields to be indexed literally.

在域(field)中的文本被索引(index)时,文本既可以被分词(tokenize)为词(term),也可以(不经过分词)依原样(literally)作为词(term)被索引(index)。大多数域(field)都是经过分词(tokenize)的,但有时对于特定标识符域(field),按照字面意思(literally)来索引(index)很有效。

See the Field java docs for more information on Fields.

有关域的更多信息,请查阅java docs文档。

Segments(段)

Lucene indexes may be composed of multiple sub-indexes, or segments. Each segment is a fully independent index, which could be searched separately. Indexes evolve by:

Lucene的索引(index)可能有多个子索引或段(segment)构成。每个段(segment)是一个完全独立的索引(index),可以单独搜索。索引(index)演变为:

  1. Creating new segments for newly added documents.
  2. Merging existing segments.
  1. 为新添加的文档(document)创建新段(segment)。
  2. 合并已有段(segment)。

Searches may involve multiple segments and/or multiple indexes, each index potentially composed of a set of segments.

搜索(search)可能涉及多个段(segment)和/或多个索引(index),每个索引(index)可能由一系列段(segment)构成。

Document Numbers(文档编号)

Internally, Lucene refers to documents by an integer document number. The first document added to an index is numbered zero, and each subsequent document added gets a number one greater than the previous.

在内部,Lucene通过整型(integer)文档(document number)编号引用文档(index)。添加到索引(index)中的首个文档(document)编号为0,后续添加的文档(document)其编号依次增长1。

Note that a document's number may change, so caution should be taken when storing these numbers outside of Lucene. In particular, numbers may change in the following situations:

注意,文档(document)的编号可能会改变,因此在Lucene外部存储文档编号(document number)时应谨慎。尤其是在以下情况中,编号可能会改变。

Index Structure Overview(索引结构概述)

Each segment index maintains the following:

每段(segment)索引(index)都包含以下内容:

Details on each of these are provided in their linked pages.

每处链接的详细信息都在链接页面中提供。

File Naming(文件命名)

All files belonging to a segment have the same name with varying extensions. The extensions correspond to the different file formats described below. When using the Compound File format (default for small segments) these files (except for the Segment info file, the Lock file, and Deleted documents file) are collapsed into a single .cfs file (see below for details)

同段(segment)中所有文件拥有相同命名与不同扩展名。扩展名对应下方对不同文件格式的描述。使用复合文件格式(默认受众为小的段(segment))时,这些文件(除段元数据文件、锁文件和删除文档文件)被折叠为单个.cfs文件()。

Typically, all segments in an index are stored in a single directory, although this is not required.

通常,一个索引(index)下的所有段(segment)存储在单个目录(dierctory)中,尽管这不是必须的。

File names are never re-used. That is, when any file is saved to the Directory it is given a never before used filename. This is achieved using a simple generations approach. For example, the first segments file is segments_1, then segments_2, etc. The generation is a sequential long integer represented in alpha-numeric (base 36) form.

文件名不会复用。也就是说,当任何文件被保存到目录时,它会被赋予一个从未使用过的文件名。这是由简单的层代(generation)方法实现的。例如,第一个段(segment)的文件为segments_1,然后是segments_2,以此类推。层代(generation)是一系列基于数字(base 36)-字母表的顺序长整数。

Summary of File Extensions(文件扩展名摘要)

The following table summarizes the names and extensions of the files in Lucene:

下方表格总结了Lucene中的文件名和扩展名:

Name(名称) Extension(扩展名) Brief Description(简介)
Segments File segments_N Stores information about a commit point.
存储提交点的信息
Lock File write.lock The Write lock prevents multiple IndexWriters from writing to the same file.
写锁可以防止多个IndexWriter写入同一文件
Segment Info .si Stores metadata about a segment.
存储段(segment)的元数据
Compound File .cfs, .cfe An optional "virtual" file consisting of all the other index files for systems that frequently run out of file handles.
一个可选的"虚拟"文件,包含经常用光的系统内所有其他索引(index)文件
Fields .fnm Stores information about the fields.
存储域(field)信息
Field Index .fdx Contains pointers to field data.
存储指向域(field)数据的指针
Field Data .fdt The stored fields for documents.
存储的文档(document)域(field)
Term Dictionary .tim The term dictionary, stores term info.
词典(term dictionary),存储词(term)信息
Term Index .tip The index into the Term Dictionary.
词典(term dictionary)中的索引(index)
Frequencies .doc Contains the list of docs which contain each term along with frequency.
包含每个词(term)及词频(term fuequency)的文档列表
Positions .pos Stores position information about where a term occurs in the index.
存储词(term)在索引(index)中出现位置信息
Payloads .pay Stores additional per-position metadata information such as character offsets and user payloads.
存储额外的位置元数据信息,如字符串的偏移量和用户有效载荷
Norms .nvd, .nvm Encodes length and boost factors for docs and fields.
编码长度和文档(document)及域(field)的提升因素
Per-Document Values .dvd, .dvm Encodes additional scoring factors or other per-document information.
编码附加打分因子(score factors)和其他每篇文档(document)信息
Term Vector Index .tvx Stores offset into the document data file.
存储到文档(document)数据文件中的偏移量(offset)
Term Vector Data .tvd Contains term vector data.
包含词向量(term vector)数据
Live Documents .liv Info about what documents are live.
哪些文档(document)是活跃的信息
Point values .dii, .dim Holds indexed points, if any.
保留被索引的点,如果有的话

Lock File(锁文件)

The write lock, which is stored in the index directory by default, is named "write.lock". If the lock directory is different from the index directory then the write lock will be named "XXXX-write.lock" where XXXX is a unique prefix derived from the full path to the index directory. When this file is present, a writer is currently modifying the index (adding or removing documents). This lock file ensures that only one writer is modifying the index at a time.

默认存储在索引(index)目录(directory)中的写入锁(lock),叫做"write.lock"。如果锁目录域与索引(index)目录不同,则写入锁被命名为"XXXX-write.lock","XXXX"是从索引(index)目录的完整路径派生的唯一前缀(prefix)。当文件存在时,一个写入程序(writer)正在修改索引(index)(添加或删除文档(document))。此锁文件确保一次只有一个写程序(writer)在修改索引(index)。

History(历史)

Compatibility notes are provided in this document, describing how file formats have changed from prior versions:

本文档提供了兼容性说明,描述了以前版本中的文件格式是如何变化的:

Limitations(限制)

Lucene uses a Java int to refer to document numbers, and the index file format uses an Int32 on-disk to store document numbers. This is a limitation of both the index file format and the current implementation. Eventually these should be replaced with either UInt64 values, or better yet, VInt values which have no limit.

Lucene使用Java int来引用文档编号,索引文件格式使用Int32 磁盘上的文档编号。这是索引文件格式和当前实现的限制。最终,这些应该被替换为任何UInt64值,或者更好的VInt是没有限制的值。

上一篇下一篇

猜你喜欢

热点阅读