问题
Until Lucene version 3.9 , we could specify to index or not to index a field by using FIELD.INDEX.NO or FIELD.INDEX.ANALYZED etc. But in lucene 4.0 there is no constructor available, in which we may define this . How do we control indexing in this version?
I mean if i want a field "name" to be stored in index but doesn't want to index it, then how can i do it in lucene 4.0?
回答1:
Constructors taking Field.Index arguments are available, but are deprecated in 4.0, and should not be used. Instead, you should look to subclasses of Field to control how a field is indexed.
StringField is the standard un-analyzed indexed field. The field is indexed is a single token. It is appropriate things like identifiers, for which you only need to search for exact matches.
TextField is the standard analyzed (and, of course, indexed) field, for textual content. It is an appropriate choice for full-text searching.
StoredField is a stored field that is not indexed at all (and so, is not searchable).
Except StoredField, each of these can be passed a Field.Store value as a constructor argument, similar to Lucene 3.6.
For more information on this change, take a look at the Lucene Migration Guide, particularly the sections titled: "Separate IndexableFieldType from Field instances"
来源:https://stackoverflow.com/questions/18564029/how-to-control-indexing-a-field-in-lucene-4-0