How to implement our own UID in Lucene?
I wish to create an index with, lets say the following fields :
UID
title
owner
content
out of which, I don't want UID to be searchable. 开发者_开发知识库[ like meta data ]
I want the UID to behave like docID so that when I want to delete or update, I'll use this. Is this possible ? How to do this ?You could mark is as non-searchable by adding it with Store.YES
and Index.NO
, but that wont allow you easy updating/removal by using it. You'll need to index the field to allow replacing it (using IndexWriter.UpdateDocument(Term, Document)
where term = new Term("UID", "...")
), so you need to use either Index.ANALYZED
with a KeywordAnalyzer
, or Index.NOT_ANALYZED
. You can also use the FieldCache
if you have a single-valued field, which a primary key usually is. However, this makes it searchable.
Summary:
Store.NO
(It can be retrieved using theFieldCache
or aTermsEnum
)Index.NOT_ANALYZED
(The complete value will be indexed as a term, including any whitespaces)
精彩评论