본문 바로가기

검색 엔진

[강한구] Lucene 색인 필드정보(.fnm)

Lucene에서 기본적으로 색인은 다음과 같이 진행한다.


IndexWriter 객체를 생성하고 (이때 색인저장은 뭐로 할지, 어디에  저장할지, 색인 analyzer는 뭘 쓸지,

                                            mode는 어떻게 할지 정합니다. {CREATE, APPEND, CREATE_OR_APPEND} 결정),

Document 객체 생성후, doc.add(new Field(xxx))를 통해서 하나의 문서를 구성한다.

마지막으로 IndexWriter.addDocument 인자로 Document 객체를 넘긴다.






이번 포스트에서는 필드 정보를 기록하는 .fnm에 대해 알아본다.

IndexWriter.addDocument 를 보면, flush(true, false)함수 호출하는 걸 볼수 있다.


(flush는 매번 호출되는게 아니라, 어떤 정책에 의해서 호출하고 있습니다. 추후에 알아봐야 겠네요.)


타고 타고 가다보면 DocFieldProcessor의 flush까지 오게 되고 결국엔 FieldInfos의 write 함수를 호출한다.


함수에 output.writeXXX를 보면 답 나온다.

IndexWriter.addDocument 부터 어떻게 문서들을 기록하는지 따라가다보면 필드명이 기존에 없는거라면

FieldInfo를 생성하고 List에 추가 한다.       아래 write 함수에서 size()는 앞에서 말한 List의 크기를 의미한다


(아...자바좀 익숙해져야겠다. Processor, Consumer 보고 멘붕왔음..)



Field Info

Field names are stored in the field info file, with suffix .fnm.

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

FNMVersion, FieldsCount --> VInt    {  output.writeVInt(CURRENT_FORMAT); output.writeVInt(size()); }

FieldName --> String                       {  output.writeString(fi.name); }

FieldBits --> Byte                            {  output.writeByte(bits); }

  • The low-order bit is one for indexed fields, and zero for non-indexed fields.
  • The second lowest-order bit is one for fields that have term vectors stored, and zero for fields without term vectors.
  • If the third lowest-order bit is set (0x04), term positions are stored with the term vectors.
  • If the fourth lowest-order bit is set (0x08), term offsets are stored with the term vectors.
  • If the fifth lowest-order bit is set (0x10), norms are omitted for the indexed field.
  • If the sixth lowest-order bit is set (0x20), payloads are stored for the indexed field.
  • If the seventh lowest-order bit is set (0x40), term frequencies and positions omitted for the indexed field.
  • If the eighth lowest-order bit is set (0x80), positions are omitted for the indexed field.

FNMVersion (added in 2.9) is -2 for indexes from 2.9 - 3.3. It is -3 for indexes in Lucene 3.4+

Fields are numbered by their order in this file. Thus field zero is the first field in the file, field one the next, and so on. Note that, like document numbers, field numbers are segment relative.