Lucene与搜索引擎技术(index包详解)

ElasticSearch特点|B+Tree|lucene倒排索引结构|lucene与elasticsearch的关系|基本概念 ElasticSearch特点 1. 天然分片,天然集群: es 把数据分成多个shard,下图中的P0-P2,多个shard可以组成一份完整的数据,这些shard可以分布在集群中的各个机器节点中。随着数据的不断增加,集群可以增加多个分片,把多个分片放到多个机子上,已达到负载均衡,横向扩展。 这种集群分片的机制造就了elasticsearch强大的数据容量及运算扩展性。 在实际运算过程中,每个查询任务提交到某一个节点,该节点必须负责将数据进行整理汇聚,再返回给客户端,也就是一个简单的节点上进行Map计算, 阅读详情

Lucene索引中有几个最基础的概念,索引(index),文档(document),域(field),和项(或者译为语词term)

其中Index为Document的序列

     Document为Field的序列

     Field为Term的序列

     Term就是一个子串  

 

存在于不同的Field中的同一个子串被认为是不同的Term.因此Term实际上是用一对子串表示的,第一个子串为Field的name,第二个为Field中的子串.既然Term这么重要,我们先来认识一下Term.  

 

 

认识Term  

 

 

最好的方法就是看其源码表示

 

 

 

public final class Term implements Comparable, java.io.Serializable {

 

 

 

  String field;

 

 

  String text;

 

 

  public Term(String fld, String txt) {this(fld, txt, true);}

 

 

 

  public final String field() { return field; }

 

 

 

 

 

 

 

 

  public final String text() { return text; }

 

 

 

 

 

 

 

 

//overwrite equals()

 

 

 

 

 

 

 

 

  public final boolean equals(Object o) { }

 

 

 

 

 

 

 

 

//overwrite hashCode()

 

 

 

 

 

 

 

 

  public final int hashCode() {return field.hashCode() + text.hashCode();

 

 

 

 

 

 

 

 

  }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  public int compareTo(Object other) {return compareTo((Term)other);}

 

 

 

 

 

 

 

 

  public final int compareTo(Term other)

 

 

 

 

 

 

 

 

  final void set(String fld, String txt)  public final String toString() { return field + ":" + text; }

 

 

 

 

 

 

 

 

  private void readObject(java.io.ObjectInputStream in)

 

 

 

 

 

 

 

 

  }

 

 

 

 

 

 

 

 

从代码中我们可以大体看出Tern其实是一个二元组

<FieldName,text>

 

 

 

 

 

 

 

 

倒排索引
为了使得基于项的搜索更有效率,索引中项是静态存储的。Lucene的索引属于索引方式中的倒排索引,因为对于一个项这种索引可以列出包含它的文档。这刚好是文档与项自然联系的倒置。

 

 

 

 

 

 

 

 

Field的类型
Lucene
中,Field的文本可能以逐字的非倒排的方式存储在索引中。而倒排过的Field称为被索引过了。Field也可能同时被存储和被索引。Field的文本可能被分解许多Term而被索引,或者就被用作一个Term而被索引。大多数的Field是被分解过的,但是有些时候某些标识符域被当做一个Term索引是很有用的。

 

 

 

 

 

 

 

 

Index包中的每个类解析

 

 

 

 

 

 

 

 

CompoundFileReader

 

 

 

 

 

 

 

 

       提供读取.cfs文件的方法

.

 

 

 

 

 

 

 

CompoundFileWriter

 

 

 

 

 

 

 

 

       用来构建.cfs文件,从Lucene1.4开始,会将下面要提到的各类文件,譬如.tii,.tis等合并成一个.cfs文件

!

 

 

 

 

 

 

 

       其结构如下

 

 

 

 

 

 

 

 

Compound (.cfs) --> FileCount, <DataOffset, FileName>FileCount, FileDataFileCount

 

 

 

 

 

 

 

FileCount --> VInt

 

 

 

 

 

 

 

DataOffset --> Long

 

 

 

 

 

 

 

FileName --> String

 

 

 

 

 

 

 

FileData --> raw file data

 

 

 

 

 

 

 

DocumentWriter

 

 

 

 

 

 

 

 

     构建.frq,.prx,.f文件   

 

 

 

 

 

 

 

 

1.FreqFile (.frq) --> <TermFreqs, SkipData>TermCount

 

 

 

 

 

 

 

TermFreqs --> <TermFreq>DocFreq

 

 

 

 

 

 

 

TermFreq --> DocDelta, Freq?

 

 

 

 

 

 

 

SkipData --> <SkipDatum>DocFreq/SkipInterval

 

 

 

 

 

 

 

SkipDatum --> DocSkip,FreqSkip,ProxSkip

 

 

 

 

 

 

 

DocDelta,Freq,DocSkip,FreqSkip,ProxSkip --> VInt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2.The .prx file contains the lists of positions that each term occurs at within documents.

 

 

 

 

 

 

 

ProxFile (.prx) --> <TermPositions>TermCount

 

 

 

 

 

 

 

TermPositions --> <Positions>DocFreq

 

 

 

 

 

 

 

Positions --> <PositionDelta>Freq

 

 

 

 

 

 

 

PositionDelta --> VInt 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3.There's a norm file for each indexed field with a byte for each document. The .f[0-9]* file contains, for each document, a byte that encodes a value that is multiplied into the score for hits on that field:

 

 

 

 

 

 

 

Norms (.f[0-9]*) --> <Byte>SegSize

 

 

 

 

 

 

 

Each byte encodes a floating point value. Bits 0-2 contain the 3-bit mantissa, and bits 3-8 contain the 5-bit exponent.

 

 

 

 

 

 

 

These are converted to an IEEE single float value as follows:

 

 

 

 

 

 

 

1.    If the byte is zero, use a zero float.

 

 

 

 

 

 

 

2.    Otherwise, set the sign bit of the float to zero;

 

 

 

 

 

 

 

3.    add 48 to the exponent and use this as the float's exponent;

 

 

 

 

 

 

 

4.    map the mantissa to the high-order 3 bits of the float's mantissa; and

 

 

 

 

 

 

 

5.    set the low-order 21 bits of the float's mantissa to zero.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

FieldInfo

 

 

 

 

 

 

 

 

      里边有Field的部分信息,是一个四元组<name,isIndexed,num,

storeTermVector>

 

 

 

 

 

 

 

FieldInfos

 

 

 

 

 

 

 

 

     此类用来描述Document的fields是否被索引.每个Segment有一个单独的FieldInfo 文件.对于多线程,此类的对象为线程安全的.但是某一时刻,只允许一个线程添加document.别的reader和writer不允许进入.此类维护两个容器ArrayList和HashMap,这两个容器都不是synchronized,何言线程安全,不解

??

 

 

 

 

 

 

 

观察write函数可知 .fnm文件的构成为

 

 

 

 

 

 

 

 

     FieldInfos (.fnm) --> FieldsCount, <FieldName, FieldBits>FieldsCount

                        FieldsCount --> VInt

 

 

 

 

 

 

 

 

                        FieldName --> String

 

 

 

 

 

 

 

 

                        FieldBits --> Byte

 

 

 

 

 

 

 

 

FieldReader

 

 

 

 

 

 

 

 

    用来读取.fdx文件和.fdt文件

 

 

 

 

 

 

 

 

FieldWriter

 

 

 

 

 

 

 

 

     此类创建两个文件.fdx和.fdt文件

 

 

 

 

 

 

 

 

     FieldIndex(.fdx)对于每一个Document,里面都含有一个指向Field的指针(其实是整数

)

 

 

 

 

 

 

 

<FieldValuesPosition>SegSize

 

 

 

 

 

 

 

FieldValuesPosition --> Uint64

 

 

 

 

 

 

 

             则第n个document的Field pointer为

n*8

 

 

 

 

 

 

 

    FieldData(.fdt)里面包含了每一个文档包含的存储的field信息.内容如下

:

 

 

 

 

 

 

 

<DocFieldData>SegSize

 

 

 

 

 

 

 

DocFieldData --> FieldCount, <FieldNum, Bits, Value>FieldCount

 

 

 

 

 

 

 

 

FieldCount --> VInt

 

 

 

 

 

 

 

 

FieldNum --> VInt

 

 

 

 

 

 

 

 

Lucene <= 1.4:

 

 

 

 

 

 

 

 

Bits --> Byte

 

 

 

 

 

 

 

 

Value --> String

 

 

 

 

 

 

 

 

Only the low-order bit of Bits is used. It is one for tokenized fields, and zero for non-tokenized fields.

 

 

 

 

 

 

 

 

FilterIndexReader

 

 

 

 

 

 

 

 

     扩展自IndexReader,提供了具体的方法

.

 

 

 

 

 

 

 

IndexReader

 

 

 

 

 

 

 

 

     为abstract class!用来读取建完索引的Directory,并可以返回各种信息,譬如Term,TermPosition等等

.

 

 

 

 

 

 

 

IndexWriter

 

 

 

 

 

 

 

 

    IndexWriter用来创建和维护索引。

 

 

 

 

 

 

 

 

    IndexWriter构造函数中的第三个参数决定一个新的索引是否被创建,或者一个存在的索引是否开放给欲新加入的新的

document

 

 

 

 

 

 

 

    通过addDocument()0函数加入新的documents,当添加完document之后,调用close()函数

 

 

 

 

 

 

 

 

    如果一个Index没有document需要加入并且需要优化查询性能。则在索引close()之前,调用optimize()函数进行优化。

 

 

 

 

 

 

 

 

    Deleteable文件结构:

 

 

 

 

 

 

 

 

   

A file named "deletable" contains the names of files that are no longer used by the index, but which could not be deleted. This is only used on Win32, where a file may not be deleted while it is still open. On other platforms the file contains only null bytes.

 

 

 

 

 

 

 

Deletable --> DeletableCount, <DelableName>DeletableCount

 

 

 

 

 

 

 

DeletableCount --> UInt32

 

 

 

 

 

 

 

DeletableName --> String

 

 

 

 

 

 

 

MultipleTermPositions

 

 

 

 

 

 

 

 

专门用于search包中的

PhrasePrefixQuery

 

 

 

 

 

 

 

MultiReader

 

 

 

 

 

 

 

 

扩展自IndexReader,用来读取多个索引!添加他们的内容

 

 

 

 

 

 

 

 

SegmentInfo

 

 

 

 

 

 

 

 

     一些关于Segment的信息,是一个三元组

<segmentname,docCount,dir>

 

 

 

 

 

 

 

SegmentInfos

 

 

 

 

 

 

 

 

     扩展自Vector,就是一个向量组,其中任意成员为SegmentInfo!用来构建segments文件,每个Index有且只有一个这样的文件,此类提供了read和write的方法

.

 

 

 

 

 

 

 

     其内容如下

:

 

 

 

 

 

 

 

    

Segments --> Format, Version, NameCounter, SegCount, <SegName, SegSize>SegCount

 

 

 

 

 

 

 

Format, NameCounter, SegCount, SegSize --> UInt32

 

 

 

 

 

 

 

Version --> UInt64

 

 

 

 

 

 

 

SegName --> String

 

 

 

 

 

 

 

Format is -1 in Lucene 1.4.

 

 

 

 

 

 

 

Version counts how often the index has been changed by adding or deleting documents.

 

 

 

 

 

 

 

NameCounter is used to generate names for new segment files.

 

 

 

 

 

 

 

SegName is the name of the segment, and is used as the file name prefix for all of the files that compose the segment's index.

 

 

 

 

 

 

 

SegSize is the number of documents contained in the segment index.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SegmentMergeInfo

 

 

 

 

 

 

 

 

    用来记录segment合并信息

.

 

 

 

 

 

 

 

SegmentMergeQueue

 

 

 

 

 

 

 

 

    扩展自PriorityQueue(按升序排列

)

 

 

 

 

 

 

 

SegmentMerger

 

 

 

 

 

 

 

 

此类合并多个Segment为一个Segment,被IndexWriter.addIndexes()创建此类对象

 

 

 

 

 

 

 

 

如果compoundFile为True即可以合并了,创建.cfs文件,并且把其余的几乎所有文件全部合并到.cfs文件中!

 

 

 

 

 

 

 

 

SegmentReader

 

 

 

 

 

 

 

 

扩展自IndexReader,提供了很多读取Index的方法

 

 

 

 

 

 

 

 

SegmentTermDocs

 

 

 

 

 

 

 

 

扩展自

TermDocs

 

 

 

 

 

 

 

SegmentTermEnum

 

 

 

 

 

 

 

 

   扩展自

TermEnum

 

 

 

 

 

 

 

SegmentTermPositions

 

 

 

 

 

 

 

 

   扩展自

TermPositions

 

 

 

 

 

 

 

SegmentTermVector

 

 

 

 

 

 

 

 

  扩展自

TermFreqVector

 

 

 

 

 

 

 

Term

 

 

 

 

 

 

 

 

     Term是一个<fieldName,text>对.而Field由于分多种,但是至少都含有<fieldName,fieldValue>这样二者就可以建立关联了.Term是一个搜索单元.Term的text都是诸如dates,email address,urls等等

.

 

 

 

 

 

 

 

TermDocs

 

 

 

 

 

 

 

 

     TermDocs是一个Interface. TermDocs提供一个接口,用来列举<document,frequency>,以共Term使用

 

 

 

 

 

 

 

 

     在<document,frequency>对中,document部分给每一个含有term的document命名.document根据其document number进行标引.frequency部分列举在每一个document中term的数量.<document,frequency>对根据document number排序

.

 

 

 

 

 

 

 

TermEnum

 

 

 

 

 

 

 

 

     此类为抽象类,用来enumerate term.Term enumerations 由Term.compareTo()进行排序此enumeration中的每一个term都要大于所有在此enumeration之前的

term.

 

 

 

 

 

 

 

TermFreqVector

 

 

 

 

 

 

 

 

     此Interface用来访问一个document的Field的

Term Vector

 

 

 

 

 

 

 

TermInfo

 

 

 

 

 

 

 

 

     此类主要用来存储Term信息.其可以说为一个五元组

<Term,docFreq,freqPointer,proxPointer,skipOffset>

 

 

 

 

 

 

 

TermInfoReader

 

 

 

 

 

 

 

 

     未细读,待读完

SegmentTermEnum

 

 

 

 

 

 

 

TermInfoWriter

 

 

 

 

 

 

 

 

     此类用来构建(.tis)和(.tii)文件.这些构成了

term dictionary

 

 

 

 

 

 

 

1.     The term infos, or tis file.

 

 

 

 

 

 

 

 

TermInfoFile (.tis)--> TIVersion, TermCount, IndexInterval, SkipInterval, TermInfos

 

 

 

 

 

 

 

 

TIVersion --> UInt32

 

 

 

 

 

 

 

 

TermCount --> UInt64

 

 

 

 

 

 

 

 

IndexInterval --> UInt32

 

 

 

 

 

 

 

 

SkipInterval --> UInt32

 

 

 

 

 

 

 

 

TermInfos --> <TermInfo>TermCount

 

 

 

 

 

 

 

 

TermInfo --> <Term, DocFreq, FreqDelta, ProxDelta, SkipDelta>

 

 

 

 

 

 

 

 

Term --> <PrefixLength, Suffix, FieldNum>

 

 

 

 

 

 

 

 

Suffix --> String

 

 

 

 

 

 

 

 

PrefixLength, DocFreq, FreqDelta, ProxDelta, SkipDelta
--> VInt

 

 

 

 

 

 

 

 

This file is sorted by Term. Terms are ordered first lexicographically by the term's field name, and within that lexicographically by the term's text.

 

 

 

 

 

 

 

 

TIVersion names the version of the format of this file and is -2 in Lucene 1.4.

 

 

 

 

 

 

 

 

Term text prefixes are shared. The PrefixLength is the number of initial characters from the previous term which must be pre-pended to a term's suffix in order to form the term's text. Thus, if the previous term's text was "bone" and the term is "boy", the PrefixLength is two and the suffix is "y".

 

 

 

 

 

 

 

 

FieldNumber determines the term's field, whose name is stored in the .fdt file.

 

 

 

 

 

 

 

 

DocFreq is the count of documents which contain the term.

 

 

 

 

 

 

 

 

FreqDelta determines the position of this term's TermFreqs within the .frq file. In particular, it is the difference between the position of this term's data in that file and the position of the previous term's data (or zero, for the first term in the file).

 

 

 

 

 

 

 

 

ProxDelta determines the position of this term's TermPositions within the .prx file. In particular, it is the difference between the position of this term's data in that file and the position of the previous term's data (or zero, for the first term in the file.

 

 

 

 

 

 

 

 

SkipDelta determines the position of this term's SkipData within the .frq file. In particular, it is the number of bytes after TermFreqs that the SkipData starts. In other words, it is the length of the TermFreq data.

 

 

 

 

 

 

 

 

2.     The term info index, or .tii file.

 

 

 

 

 

 

 

 

This contains every IndexIntervalth entry from the .tis file, along with its location in the "tis" file. This is designed to be read entirely into memory and used to provide random access to the "tis" file.

 

 

 

 

 

 

 

 

The structure of this file is very similar to the .tis file, with the addition of one item per record, the IndexDelta.

 

 

 

 

 

 

 

 

TermInfoIndex (.tii)--> TIVersion, IndexTermCount, IndexInterval, SkipInterval, TermIndices

 

 

 

 

 

 

 

 

TIVersion --> UInt32

 

 

 

 

 

 

 

 

IndexTermCount --> UInt64

 

 

 

 

 

 

 

 

IndexInterval --> UInt32

 

 

 

 

 

 

 

 

SkipInterval --> UInt32

 

 

 

 

 

 

 

 

TermIndices --> <TermInfo, IndexDelta>IndexTermCount

 

 

 

 

 

 

 

 

IndexDelta --> VLong

 

 

 

 

 

 

 

 

IndexDelta determines the position of this term's TermInfo within the .tis file. In particular, it is the difference between the position of this term's entry in that file and the position of the previous term's entry.

 

 

 

 

 

 

 

 

TODO: document skipInterval information

 

 

 

 

 

 

 

 

             其中IndexDelta是.tii文件,比之.tis文件多的东西

.

 

 

 

 

 

 

 

TermPosition

 

 

 

 

 

 

 

 

      此类扩展自TermDocs,是一个Interface,用来enumerate<document,frequency,<position>*>三元组

,

 

 

 

 

 

 

 

以供term使用.在此三元组中document和frequency于TernDocs中的相同.postions部分列出了在一个document中,一个term每次出现的顺序位置此三元组为倒排文档的事件表表示

.

 

 

 

 

 

 

 

TermPositionVector

 

 

 

 

 

 

 

 

      扩展自TermFreqVector.比之TermFreqVector扩展了功能,可以提供term所在的位置

 

 

 

 

 

 

 

 

TermVectorReader

 

 

 

 

 

 

 

 

      用来读取.tvd,.tvf.tvx三个文件

.

 

 

 

 

 

 

 

TermVectorWriter

 

 

 

 

 

 

 

 

      用于构建.tvd, .tvf,.tvx文件,这三个文件构成

TermVector

 

 

 

 

 

 

 

 

1.    The Document Index or .tvx file.

 

 

 

 

 

 

 

This contains, for each document, a pointer to the document data in the Document (.tvd) file.

 

 

 

 

 

 

 

DocumentIndex (.tvx) --> TVXVersion<DocumentPosition>NumDocs

 

 

 

 

 

 

 

TVXVersion --> Int

 

 

 

 

 

 

 

DocumentPosition --> UInt64

 

 

 

 

 

 

 

This is used to find the position of the Document in the .tvd file.

 

 

 

 

 

 

 

2.    The Document or .tvd file.

 

 

 

 

 

 

 

This contains, for each document, the number of fields, a list of the fields with term vector info and finally a list of pointers to the field information in the .tvf (Term Vector Fields) file.

 

 

 

 

 

 

 

Document (.tvd) --> TVDVersion<NumFields, FieldNums, FieldPositions,>NumDocs

 

 

 

 

 

 

 

TVDVersion --> Int

 

 

 

 

 

 

 

NumFields --> VInt

 

 

 

 

 

 

 

FieldNums --> <FieldNumDelta>NumFields

 

 

 

 

 

 

 

FieldNumDelta --> VInt

 

 

 

 

 

 

 

FieldPositions --> <FieldPosition>NumFields

 

 

 

 

 

 

 

FieldPosition --> VLong

 

 

 

 

 

 

 

The .tvd file is used to map out the fields that have term vectors stored and where the field information is in the .tvf file.

 

 

 

 

 

 

 

3.    The Field or .tvf file.

 

 

 

 

 

 

 

This file contains, for each field that has a term vector stored, a list of the terms and their frequencies.

 

 

 

 

 

 

 

Field (.tvf) --> TVFVersion<NumTerms, NumDistinct, TermFreqs>NumFields

 

 

 

 

 

 

 

TVFVersion --> Int

 

 

 

 

 

 

 

NumTerms --> VInt

 

 

 

 

 

 

 

NumDistinct --> VInt -- Future Use

 

 

 

 

 

 

 

TermFreqs --> <TermText, TermFreq>NumTerms

 

 

 

 

 

 

 

TermText --> <PrefixLength, Suffix>

 

 

 

 

 

 

 

PrefixLength --> VInt

 

 

 

 

 

 

 

Suffix --> String

 

 

 

 

 

 

 

TermFreq --> VInt

 

 

 

 

 

 

 

Term text prefixes are shared. The PrefixLength is the number of initial characters from the previous term which must be pre-pended to a term's suffix in order to form the term's text. Thus, if the previous term's text was "bone" and the term is "boy", the PrefixLength is two and the suffix is "y".

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

好的,整个Index包所有类都讲解了,下边咱们开始来编码重新审视一下!

 

 

 

 

 

 

 

 

下边来编制一个程序来结束本章的讨论。

 

 

 

 

 

 

 

 

package org.apache.lucene.index;

 

 

 

 

 

 

 

 

import org.apache.lucene.analysis.*;

 

 

 

 

 

 

 

 

import org.apache.lucene.analysis.standard.*;

 

 

 

 

 

 

 

 

import org.apache.lucene.store.*;

 

 

 

 

 

 

 

 

import org.apache.lucene.document.*;

 

 

 

 

 

 

 

 

import org.apache.lucene.demo.*;

 

 

 

 

 

 

 

 

import org.apache.lucene.search.*;

 

 

 

 

 

 

 

 

import java.io.*;

 

 

 

 

 

 

 

 

/**在使用此程序时,会尽量用到Lucene Index中的每一个类,尽量将其展示个大家

 

 

 

 

 

 

 

 

 *使用的Index包中类有

 

 

 

 

 

 

 

 

 *DocumentWriter(提供给用用户使用的为IndexWriter)

 

 

 

 

 

 

 

 

 *FieldInfo(和FieldInfos)

 

 

 

 

 

 

 

 

 * SegmentDocs(扩展自TermDocs)

 

 

 

 

 

 

 

 

 *SegmentReader(扩展自IndexReader,提供给用户使用的是IndexReader)

 

 

 

 

 

 

 

 

 *SegmentMerger

 

 

 

 

 

 

 

 

 *segmentTermEnum(扩展自TermEnum)

 

 

 

 

 

 

 

 

 *segmentTermPositions(扩展自TermPositions)

 

 

 

 

 

 

 

 

 *segmentTermVector(扩展自TermFreqVector)

 

 

 

 

 

 

 

 

*/

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

public class TestIndexPackage

 

 

 

 

 

 

 

 

{

 

 

 

 

 

 

 

 

  //用于将Document加入索引

 

 

 

 

 

 

 

 

  public static void indexDocument(String segment,String fileName) throws Exception

 

 

 

 

 

 

 

 

  {

 

 

 

 

 

 

 

 

    //第二个参数用来控制,如果获得不了目录是否创建

 

 

 

 

 

 

 

 

    Directory directory = FSDirectory.getDirectory("testIndexPackage",false);

 

 

 

 

 

 

 

 

    Analyzer analyzer = new SimpleAnalyzer();

 

 

 

 

 

 

 

 

    //第三个参数为每一个Field最多拥有的Token个数

 

 

 

 

 

 

 

 

    DocumentWriter writer = new DocumentWriter(directory,analyzer,Similarity.getDefault(),1000);

 

 

 

 

 

 

 

 

    File file = new File(fileName);

 

 

 

 

 

 

 

 

    //由于使用FileDocument将file包装成了Docuement,会在document中创建三个field(path,modified,contents)

 

 

 

 

 

 

 

 

    Document doc = FileDocument.Document(file);

 

 

 

 

 

 

 

 

    writer.addDocument(segment,doc);

 

 

 

 

 

 

 

 

    directory.close();

 

 

 

 

 

 

 

 

  }

 

 

 

 

 

 

 

 

  //将多个segment进行合并

 

 

 

 

 

 

 

 

  public static void merge(String segment1,String segment2,String segmentMerged)throws Exception

 

 

 

 

 

 

 

 

  {

 

 

 

 

 

 

 

 

    Directory directory = FSDirectory.getDirectory("testIndexPackage",false);

 

 

 

 

 

 

 

 

    SegmentReader segmentReader1=new SegmentReader(new SegmentInfo(segment1,1,directory));

 

 

 

 

 

 

 

 

    SegmentReader segmentReader2=new SegmentReader(new SegmentInfo(segment2,1,directory));

 

 

 

 

 

 

 

 

    //第三个参数为是否创建.cfs文件

 

 

 

 

 

 

 

 

    SegmentMerger segmentMerger =new SegmentMerger(directory,segmentMerged,false);

 

 

 

 

 

 

 

 

    segmentMerger.add(segmentReader1);

 

 

 

 

 

 

 

 

    segmentMerger.add(segmentReader2);

 

 

 

 

 

 

 

 

    segmentMerger.merge();

 

 

 

 

 

 

 

 

    segmentMerger.closeReaders();

 

 

 

 

 

 

 

 

    directory.close();

 

 

 

 

 

 

 

 

  }

 

 

 

 

 

 

 

 

  //将segment即Index的子索引的所有内容展示给你看。

 

 

 

 

 

 

 

 

  public static void printSegment(String segment) throws Exception

 

 

 

 

 

 

 

 

  {

 

 

 

 

 

 

 

 

    Directory directory =FSDirectory.getDirectory("testIndexPackage",false);

 

 

 

 

 

 

 

 

    SegmentReader segmentReader = new SegmentReader(new SegmentInfo(segment,1,directory));

 

 

 

 

 

 

 

 

    //display documents

 

 

 

 

 

 

 

 

    for(int i=0;i<segmentReader.numDocs();i++)

 

 

 

 

 

 

 

 

      System.out.println(segmentReader.document(i));

 

 

 

 

 

 

 

 

    TermEnum termEnum = segmentReader.terms();//此处实际为

SegmentTermEnum

 

 

 

 

 

 

 

 

    //display term and term positions,termDocs

 

 

 

 

 

 

 

 

    while(termEnum.next())

 

 

 

 

 

 

 

 

    {

 

 

 

 

 

 

 

 

      System.out.print(termEnum.term().toString2());

 

 

 

 

 

 

 

 

      System.out.println(" DocumentFrequency=" + termEnum.docFreq());

 

 

 

 

 

 

 

 

      TermPositions termPositions= segmentReader.termPositions(termEnum.term());

 

 

 

 

 

 

 

 

      int i=0;

 

 

 

 

 

 

 

 

      while(termPositions.next())

 

 

 

 

 

 

 

 

      {

 

 

 

 

 

 

 

 

        System.out.println((i++)+"->"+termPositions);

 

 

 

 

 

 

 

 

      }

 

 

 

 

 

 

 

 

      TermDocs termDocs=segmentReader.termDocs(termEnum.term());//实际为

segmentDocs

 

 

 

 

 

 

 

 

      while (termDocs.next())

 

 

 

 

 

 

 

 

      {

 

 

 

 

 

 

 

 

        System.out.println((i++)+"->"+termDocs);

 

 

 

 

 

 

 

 

      }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

    }

 

 

 

 

 

 

 

 

    //display field info

 

 

 

 

 

 

 

 

    FieldInfos fieldInfos= segmentReader.fieldInfos;

 

 

 

 

 

 

 

 

    FieldInfo pathFieldInfo = fieldInfos.fieldInfo("path");

 

 

 

 

 

 

 

 

    FieldInfo modifiedFieldInfo = fieldInfos.fieldInfo("modified");

 

 

 

 

 

 

 

 

    FieldInfo contentsFieldInfo =fieldInfos.fieldInfo("contents");

 

 

 

 

 

 

 

 

    System.out.println(pathFieldInfo);

 

 

 

 

 

 

 

 

    System.out.println(modifiedFieldInfo);

 

 

 

 

 

 

 

 

    System.out.println(contentsFieldInfo);

 

 

 

 

 

 

 

 

   //display TermFreqVector

 

 

 

 

 

 

 

 

   for(int i=0;i<segmentReader.numDocs();i++)

 

 

 

 

 

 

 

 

   {

 

 

 

 

 

 

 

 

     //对contents的token之后的term存于了

TermFreqVector

 

 

 

 

 

 

 

 

     TermFreqVector termFreqVector=segmentReader.getTermFreqVector(i,"contents");

 

 

 

 

 

 

 

 

     System.out.println(termFreqVector);

 

 

 

 

 

 

 

 

   }

 

 

 

 

 

 

 

 

  }

 

 

 

 

 

 

 

 

  public static void main(String [] args)

 

 

 

 

 

 

 

 

  {

 

 

 

 

 

 

 

 

    try

 

 

 

 

 

 

 

 

    {

 

 

 

 

 

 

 

 

      Directory directory = FSDirectory.getDirectory("testIndexPackage",true);

 

 

 

 

 

 

 

 

      directory.close();

 

 

 

 

 

 

 

 

      indexDocument("segmentOne","e://lucene//test.txt");

 

 

 

 

 

 

 

 

      //printSegment("segmentOne");

 

 

 

 

 

 

 

 

      indexDocument("segmentTwo","e://lucene//test2.txt");

 

 

 

 

 

 

 

 

     // printSegment("segmentTwo");

 

 

 

 

 

 

 

 

      merge("segmentOne","segmentTwo","merge");

 

 

 

 

 

 

 

 

      printSegment("merge");

 

 

 

 

 

 

 

 

    }

 

 

 

 

 

 

 

 

    catch(Exception e)

 

 

 

 

 

 

 

 

    {

 

 

 

 

 

 

 

 

      System.out.println("caught a "+e.getCause()+"/n with message:"+e.getMessage());

 

 

 

 

 

 

 

 

      e.printStackTrace();

 

 

 

 

 

 

 

 

    }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  }

 

 

 

 

 

 

 

 

}

 

 

 

 

 

 

 

 

看看其结果如下:

 

 

 

 

 

 

 

 

Document<Text<path:e:/lucene/test.txt> Keyword<modified:0eg4e221c>>

 

 

 

 

 

 

 

 

Document<Text<path:e:/lucene/test2.txt> Keyword<modified:0eg4ee8b4>>

 

 

 

 

 

 

 

 

<Term:FieldName,text>=<contents,china> DocumentFrequency=1

 

 

 

 

 

 

 

 

0-><doc,TermFrequency,Pos>:< doc=0, TermFrequency=1 Pos=2>

 

 

 

 

 

 

 

 

1-><docNumber,freq>=<0,1>

 

 

 

 

 

 

 

 

<Term:FieldName,text>=<contents,i> DocumentFrequency=2

 

 

 

 

 

 

 

 

0-><doc,TermFrequency,Pos>:< doc=0, TermFrequency=2 Pos=0,3>

 

 

 

 

 

 

 

 

1-><doc,TermFrequency,Pos>:< doc=1, TermFrequency=1 Pos=0>

 

 

 

 

 

 

 

 

2-><docNumber,freq>=<0,2>

 

 

 

 

 

 

 

 

3-><docNumber,freq>=<1,1>

 

 

 

 

 

 

 

 

<Term:FieldName,text>=<contents,love> DocumentFrequency=2

 

 

 

 

 

 

 

 

0-><doc,TermFrequency,Pos>:< doc=0, TermFrequency=2 Pos=1,4>

 

 

 

 

 

 

 

 

1-><doc,TermFrequency,Pos>:< doc=1, TermFrequency=1 Pos=1>

 

 

 

 

 

 

 

 

2-><docNumber,freq>=<0,2>

 

 

 

 

 

 

 

 

3-><docNumber,freq>=<1,1>

 

 

 

 

 

 

 

 

<Term:FieldName,text>=<contents,nankai> DocumentFrequency=1

 

 

 

 

 

 

 

 

0-><doc,TermFrequency,Pos>:< doc=1, TermFrequency=1 Pos=2>

 

 

 

 

 

 

 

 

1-><docNumber,freq>=<1,1>

 

 

 

 

 

 

 

 

<Term:FieldName,text>=<contents,tianjin> DocumentFrequency=1

 

 

 

 

 

 

 

 

0-><doc,TermFrequency,Pos>:< doc=0, TermFrequency=1 Pos=5>

 

 

 

 

 

 

 

 

1-><docNumber,freq>=<0,1>

 

 

 

 

 

 

 

 

<Term:FieldName,text>=<modified,0eg4e221c> DocumentFrequency=1

 

 

 

 

 

 

 

 

0-><doc,TermFrequency,Pos>:< doc=0, TermFrequency=1 Pos=0>

 

 

 

 

 

 

 

 

1-><docNumber,freq>=<0,1>

 

 

 

 

 

 

 

 

<Term:FieldName,text>=<modified,0eg4ee8b4> DocumentFrequency=1

 

 

 

 

 

 

 

 

0-><doc,TermFrequency,Pos>:< doc=1, TermFrequency=1 Pos=0>

 

 

 

 

 

 

 

 

1-><docNumber,freq>=<1,1>

 

 

 

 

 

 

 

 

<Term:FieldName,text>=<path,e> DocumentFrequency=2

 

 

 

 

 

 

 

 

0-><doc,TermFrequency,Pos>:< doc=0, TermFrequency=1 Pos=0>

 

 

 

 

 

 

 

 

1-><doc,TermFrequency,Pos>:< doc=1, TermFrequency=1 Pos=0>

 

 

 

 

 

 

 

 

2-><docNumber,freq>=<0,1>

 

 

 

 

 

 

 

 

3-><docNumber,freq>=<1,1>

 

 

 

 

 

 

 

 

<Term:FieldName,text>=<path,lucene> DocumentFrequency=2

 

 

 

 

 

 

 

 

0-><doc,TermFrequency,Pos>:< doc=0, TermFrequency=1 Pos=1>

 

 

 

 

 

 

 

 

1-><doc,TermFrequency,Pos>:< doc=1, TermFrequency=1 Pos=1>

 

 

 

 

 

 

 

 

2-><docNumber,freq>=<0,1>

 

 

 

 

 

 

 

 

3-><docNumber,freq>=<1,1>

 

 

 

 

 

 

 

 

<Term:FieldName,text>=<path,test> DocumentFrequency=2

 

 

 

 

 

 

 

 

0-><doc,TermFrequency,Pos>:< doc=0, TermFrequency=1 Pos=2>

 

 

 

 

 

 

 

 

1-><doc,TermFrequency,Pos>:< doc=1, TermFrequency=1 Pos=2>

 

 

 

 

 

 

 

 

2-><docNumber,freq>=<0,1>

 

 

 

 

 

 

 

 

3-><docNumber,freq>=<1,1>

 

 

 

 

 

 

 

 

<Term:FieldName,text>=<path,txt> DocumentFrequency=2

 

 

 

 

 

 

 

 

0-><doc,TermFrequency,Pos>:< doc=0, TermFrequency=1 Pos=3>

 

 

 

 

 

 

 

 

1-><doc,TermFrequency,Pos>:< doc=1, TermFrequency=1 Pos=3>

 

 

 

 

 

 

 

 

2-><docNumber,freq>=<0,1>

 

 

 

 

 

 

 

 

3-><docNumber,freq>=<1,1>

 

 

 

 

 

 

 

 

<fieldName,isIndexed,fieldNumber,storeTermVector>=path,true,3,false>

 

 

 

 

 

 

 

 

<fieldName,isIndexed,fieldNumber,storeTermVector>=modified,true,2,false>

 

 

 

 

 

 

 

 

<fieldName,isIndexed,fieldNumber,storeTermVector>=contents,true,1,true>

 

 

 

 

 

 

 

 

{contents: china/1, i/2, love/2, tianjin/1}

 

 

 

 

 

 

 

 

{contents: i/1, love/1, nankai/1}

 

 

 

 

 

 

 

 

认真审视其结果,你就会更加明白Lucene底层的索引结构如何。

 

 

 

 

 

 

 

参考资料:Lucene File Format

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

从Lucene到ElasticSearch:分布式搜索引擎的架构演进与核心抽象 本文详细探讨了从Lucene到ElasticSearch的分布式搜索引擎架构演进历程,重点分析了ElasticSearch在Lucene基础上的分布式创新与核心抽象设计。通过对比单机Lucene的性能局限与ES的自动分片、副本机制等优势,结合电商搜索等实战案例,展示了现代搜索引擎的最佳实践与优化技巧,为开发者提供架构演进参考。 阅读详情

相关推荐

ElasticSearch搜索引擎入门到精通

ES 是基于 Lucene 的全文检索引擎,它会对数据进行分词后保存索引,擅长管理大量的数据,相对于 MySQL 来说不擅长经常更新数据及关联查询。这篇文章就是为了进一步了解一下它,到底是如何做到这么高效的查询的。在学习其他数据库的时候我们知道是一个数据库系统极其重要的部分,它直接决定着查询的效率。ES之所以快,是因为其底层的Lucene采用倒排索引的方式,并且还有很多的优化点,

青玉白露的博客 1583

Elasticsearch 中的一些重要概念: cluster, node, index, document, shards 及 replica

当我们开始使用Elasticsearch时,我们必须理解其中的一些重要的概念。这些概念的理解对于以后我们使用Elastic栈是非常重要的。在今天的这篇文章里,我们先来介绍一下在Elastic栈中最重要的一些概念。 首先,我们来看下一下如下的这个图: Cluster Cluster也就是集群的意思。Elasticsearch集群由一个或多个节点组成,可通过其集群名称进行标识。通常这个........................

Elastic 中国社区官方博客 3万+

实时搜索引擎Elasticsearch(1)——基础概念、安装和运行

Elasticsearch(简称ES)是一个基于Apache Lucene(TM)的开源搜索引擎,无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进、性能最好的、功能最全的搜索引擎库。本文介绍它的基础概念、安装、运行以及配置。

HinyLover的专栏 2万+

ElasticSearch分片与Lucene Index

ElasticSearch分片与Lucene Index以及倒排索引

xhl1123456789的博客 1603

Elasticsearch (ES)+Kibana简单使用

前言 es是一个强大的搜索引擎,目前知名公司内部都在使用! 因为Elasticsearch 是一个基于 Apache Lucene™ 的开源搜索引擎。无论在开源还是专有领域,Lucene 可以被认为是迄今为止最先进、性能最好的、功能最全的搜索引擎库。 首先我们要知道,es虽然强大,但是不方便操作,所以我们需要借助于kibana工具来进行开发! kibana 本篇不讲kibana和es的安装,后面会专门写安装过程。这里先知道kibana工具是提供了一个可视化的界面。 我们的es需要以基于 HTTP 协议,以

Mr.Zheng的博客 1万+

「Elasticsearch + Lucene」搜索引擎的架构、倒排索引和搜索过程

从一个浪漫的故事开始 许多年前,一个名叫Shay Banon的开发者,带着新婚妻子去伦敦生活,在得知妻子想从事厨师工作后,准备利用自己所学为妻子开发一个食谱搜索引擎,他开始使用Lucene的一个早期版本。但是尝试之后,他发现直接使用Lucene给没有任何开发经验的妻子而言是非常困难的,因此Shay 开始对Lucene进行封装。不久他发布了他的第一个基于Lucene的用java编写的开...

AI天才研究院 9002

【搜索引擎】一文搞懂elastic search核心概念:倒排索引、lucene

一文搞懂ES核心概念:倒排索引、lucene。

BugMan的博客 1469

LS-DYNA中的流固耦合

在LS-DYNA中对流固耦合问题的求解提供了两种方法,ALE流固耦合和基于ICFD的流固耦合。本文将对两种方法的各自特点进行分析。 ALE方法的流固耦合 适用范围 ALE求解器主要用于层流。ALE求解器也不是完全的NS求解器,因此不考虑边界层的影响,比如阻力。流体粘性效应仅通过材料模型获得,也就是*mat_null的MU。ale求解器是为了求解高压高速度梯度的短时问题而开发的。该求解器并不适用于求解低压力梯度问题比如声学,也不适用于长时间问题(秒的尺度甚至更长)。时间的限制是显式时...

m0_69812055的博客 8571

搜索引擎面面观 lucene 和 es 的前世今生

搜索引擎面面观 lucene 和 es 的前世今生   lucene 是最先进、功能最强大的搜索库。如果直接基于 lucene 开发,非常复杂,即便写一些简单的功能,也要写大量的 Java 代码,需要深入理解原理。 elasticsearch 基于 lucene,隐藏了 lucene 的复杂性,提供了简单易用的 restful api / Java api 接口(另外还有其他语言的 ap...

wenlin_xie的专栏 596

踩坑ubuntu24.04 编译vtk9.3.1的安卓版本

NDK官方明确废弃了旧版 armeabi ABI,强制使用armeabi-v7a或arm64-v8a。错误信息显示你的构建系统仍在使用超级构建(superbuild)模式,并且内部引用了已不再支持的。生成的合并库: $(pwd)/libvtk_combined.a"超级构建过程可能内部未充分考虑现代NDK变化导致内部配置ARM老ABI,重复失败。echo "正在提取所有.o文件..."echo "合并前所有库的总大小:"# 提取所有.a文件中的.o文件。echo "创建合并库..."

zhangyihu321的专栏 1908

2021.11.23 Covins 多机器人单目协同建图 跑Euroc数据集 更新

近日,一直在调试如何使用Covins跑通数据集,因为是初学者,所以很多bug出来的时候原理都不懂,只能复制——百度——尝试解决的过程。 现分享一下近日的结果以及与Covins作者帮助解答的一些问题。 使用代码行跑依次跑Euroc多数据集 这里的意思是使用作者提供的covins_examples文件夹中的euroc_examples_mh123_vigba.sh文件,这个文件是将三个Euroc数据集依次运行,跑完第一个数据集,第二个数据集运行的时候在第一个数据集生成地图的基础上继续绘制,由于我只下载了两个数据

qq_42614598的博客 2484

Elasticsearch 倒排索引中词条索引原理分析 — 基于 Lucene FST(ES 7 / Lucene 8)

Elasticsearch 倒排索引中词条索引原理分析 — 基于 Lucene FST(ES 7 / Lucene 8)

J_bean的博客 876

物联网定位技术|实验报告|实验一 Wi-Fi指纹定位

全球定位系统是迄今为止应用最为成功的地位系统,具备高精度的定位能力,但在室内和高楼密布的城区等信号遮挡严重的密集环境中,由于接受机捕获不到足够强度的卫星信号,GPS的定位质量难以保证甚至无法完成定位,使其可用性受到严重制约。由于室内环境下都普及了WiFi,因此利用WiFi进行定位无需额外部署硬件设备,是一个非常节省成本的方法。

m0_57656758的博客 3366

Elasticsearch-3--什么是Lucene?

Lucene是一个Java编写的全文检索引擎库,而非完整的搜索引擎。它提供了一个可扩展的架构,开发者可以基于Lucene构建自定义的搜索系统。索引引擎:将文本数据转换为倒排索引(Inverted Index)。查询引擎:支持复杂的全文搜索和过滤。文本分析引擎:提供分词、词干提取、停用词过滤等文本处理功能。示例:Lucene = 搜索引擎的“发动机”,你需要自己造一辆“车”来搭载它,如ES就相当于是一辆车。

weisian的博客 3万+

华为OD机考2025C卷 - 精准核酸检测(Java & Python& JS & C++ & C语言)

华为OD机考2025C卷 - 精准核酸检测,提供在线OJ Java & Python& JS & C++ & C

算法大师! 2895

【RT-DETR有效改进】利用MobileNetV3替换Backbone(轻量化网络结构,提点)

本文给大家带来的改进机制是,其主要改进思想集中在结合硬件感知的网络架构搜索(NAS)和NetAdapt算法,以优化移动设备CPU上的性能。它采用了新颖的架构设计,包括反转残差结构和线性瓶颈层,以及新的高效分割解码器Lite Reduced Atrous Spatial Pyramid Pooling(LR-ASPP),以提升在移动分类、检测和分割任务上的表现。实验表明,MobileNets在资源和准确性的权衡方面表现出色,并在多种应用(如对象检测、细粒度分类、面部属性识别和大规模地理定位)中展现了其有效性。

Snu77的博客 2758

Elasticsearch - Elasticsearch 中的 Lucene 段合并策略深度解析

摘要 本文深入解析Elasticsearch底层Lucene的段合并机制。首先介绍Lucene段(Segment)的概念及其"写时复制"设计优势,说明段合并的必要性。然后详细分析三种合并策略:默认的TieredMergePolicy(分层策略)、已弃用的LogByteSizeMergePolicy以及实验中的UnifiedMergePolicy,重点讲解TieredMergePolicy的核心参数与工作原理。文章还提供Elasticsearch中的合并配置方法和Java代码示例,演示如何

千淘万漉虽辛苦,吹尽狂沙始到金 2万+

[deprecated]第二章:DRM 框架概述:2.2 GEM显存管理概述

本文深入分析了Linux DRM子系统中GEM(Graphics Execution Manager)的显存管理机制。GEM通过核心数据结构drm_gem_object抽象显存buffer,结合drm_vma_offset_manager和drm_mm实现高效的地址空间分配与管理。该系统支持显存动态分配/回收、用户空间mmap映射、多进程访问隔离和跨设备共享等关键功能,并通过引用计数和同步机制确保并发安全。

图形/计算GPU的驱动与虚拟化技术分享园地 2584

ElasticSearch全文搜索引擎

搜索引擎是一种能够帮助用户在互联网上查找相关信息的工具。它通过扫描并索引全球各种网站中的内容,然后根据用户输入的关键词,返回与其搜索意图最相关的网页。搜索引擎摘要是在搜索结果页面上显示的简短描述,用于提供关于搜索结果的基本信息。摘要通常包括关键词、有关内容的片段和相关信息,旨在帮助用户快速了解搜索结果的相关性,并决定是否点击查看完整内容。通过优化搜索引擎摘要,提供准确、吸引人且有用的描述,用户能够更好地评估搜索结果的质量,提高搜索效率。搜索引擎摘要在用户体验和搜索引擎优化中起着重要作用。

m0_64254759的博客 721

Open-Sora代码详细解读(1):解读DiT结构

目前开源的DiT视频生成模型不是很多,Open-Sora是开发者生态最好的一个,涵盖了DiT、时空DiT、3D VAE、Rectified Flow、因果卷积等Diffusion视频生成的经典知识点。本篇博客从Open-Sora的代码出发,深入解读背后的原理。

沉迷单车的追风少年 2275

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Elasticsearch 架构及 Lucene 索引结构原理入门

Elasticsearch 架构及 Lucene 索引结构原理入门

虽非技冠群英首,愿与同道共长歌; 大鹏一日同风起,扶摇直上九万里; 1743

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

ElasticSearch

ElasticSearch

小钟不想敲代码 6722

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

elasticsearch(ES)

1、为什么要使用搜索框架? 2、Lucene的介绍 3、Lucene和ES的区别? 4、ES的安装 为什么要使用ES或者Lucene?   之前我们接触的都是模糊查询,,但模糊查询不够准确,有很大的局限性!   比如:我爱Java 在模糊查询中:%我爱Java%   但正常情况下我们网页上的搜索:我爱.....;......Java....

dayiyang9635的博客 180

es index包

因为你已经学过 Lucene,看到这里就会有一种“到家了”的亲切感,知道它是怎么把 Lucene 的能力暴露给上层的。5. 配置与策略:看代码时可以留意 IndexSettings 和 MergePolicyConfig 等类,它们定义了索引的行为,比如 IndexSortConfig 决定了索引的排序方式,MergePolicyConfig 控制着 Lucene 底层的段合并策略。A[IndexModule<br>索引的“组装工厂”] --> B[IndexService<br>索引在节点上的“门面”]

risc123456的博客 253
上一篇: Lucene倒排索引原理
下一篇: DataInputStream与DataOutputStream的用法
Java2King
博客等级 码龄18年 221粉丝 77原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址