Monday, August 1, 2011

Lucene Field Options

Field Indexing Option

Field.Index.ANALYZED : Use analyzer to break the field's value into separate tokens and make each token searchable. This option is useful for body, title, abstract text.

Field.Index.NOT_ANALYZED : Index the field but don't analyze the string value. Instead, treat the field's value as a single token and make the token searchable. This option is useful for URL, file system path, dates, personal names, card number, phone number. This option is useful for enabling "exact match" searching.

Field.Index.NO : Don't make the field's value available for searching

Field Storing Option

Field.Store.YES : Store field's value in the index. This option is useful for fields that we want to display along with the search result such as URL, title, database primary key. Without storing the field's value, we won't be able to retrieve it using document.get("fieldname") on searching.

Field.Store.NO : Don't store the field's value in the index. This option is often used along with Field.Index.ANALYZED to index large text field such as text body.

Here are some example of field indexing and field storing option:

Analyzed & Stored : title, abstract text
Analyzed & Not Stored : body
Not Analyzed & Stored : URL, file system path, dates, personal names, card number, phone number
No Index & Stored : database primary key
Not Analyzed & Not Stored : hidden keywords

Code Example:

Document document = new Document();
document.add(new Field("filename", file.getName(), Field.Store.YES, Field.Index.NOT_ANALYZED));
indexWriter.addDocument(document );

0 comments:

 

©2009 Stay the Same | by TNB