Book Image

Lucene 4 Cookbook

By : Edwood Ng, Vineeth Mohan
Book Image

Lucene 4 Cookbook

By: Edwood Ng, Vineeth Mohan

Overview of this book

Table of Contents (16 chapters)
Lucene 4 Cookbook
About the Authors
About the Reviewers

Un-inverting single-valued fields in memory with FieldCache

We have learned very early on that Lucene stores data in an inverted index in which terms are sorted and DocId is associated with each term. A search is essentially finding DocId's intersection in matched terms. The index itself allows for a very fast term lookup, but it's not ideal for lookup by DocId. To solve the problem of finding a field value by DocId, Lucene introduced FieldCache. FieldCache is an in-memory data structure that stored in an array format in which the value position corresponds to DocId (since DocId is basically an ordinal value of all documents). Because each array position can only store one value, FieldCache should be used on single-valued fields only. In essence, Lucene uninverts data from the index and stores them in FieldCache.


Note that when FieldCache is initialized, it stays static and it does not synchronize with IndexReader. If you need to reopen IndexReader, FieldCache will need to be reinitialized...