📜  Lucene-索引类

📅  最后修改于: 2020-11-12 04:45:28             🧑  作者: Mango


索引过程是Lucene提供的核心功能之一。下图说明了索引编制过程和类的使用。 IndexWriter是索引过程中最重要的也是核心组件。

索引过程

我们将包含字段的文档添加到IndexWriter,后者使用分析器分析文档,然后根据需要创建/打开/编辑索引,并将其存储/更新到Directory中。 IndexWriter用于更新或创建索引。它不用于读取索引。

索引类

以下是索引过程中常用类的列表。

S.No. Class & Description
1 IndexWriter

This class acts as a core component which creates/updates indexes during the indexing process.

2 Directory

This class represents the storage location of the indexes.

3 Analyzer

This class is responsible to analyze a document and get the tokens/words from the text which is to be indexed. Without analysis done, IndexWriter cannot create index.

4 Document

This class represents a virtual document with Fields where the Field is an object which can contain the physical document’s contents, its meta data and so on. The Analyzer can understand a Document only.

5 Field

This is the lowest unit or the starting point of the indexing process. It represents the key value pair relationship where a key is used to identify the value to be indexed. Let us assume a field used to represent contents of a document will have key as “contents” and the value may contain the part or all of the text or numeric content of the document. Lucene can index only text or numeric content only.