lucene6版本较之最初的版本在字段类型上还是有蛮大区别的,今天重点介绍其中的两个:TextField与StringField,下面直接看源码:
代码语言:javascript复制public final class TextField extends Field {
/** Indexed, tokenized, not stored. */
public static final FieldType TYPE_NOT_STORED = new FieldType();
/** Indexed, tokenized, stored. */
public static final FieldType TYPE_STORED = new FieldType();
从上面代码可以看出,TextField肯定会进行语汇化,比如Lucene in Action经过语汇后会删除中间的in字符,这样通过TermQuery q1 = new TermQuery(new Term("title","Lucene in Action"));创建的查询将找不到“lucene in action”。
相反我们下面看看StringField类:
代码语言:javascript复制 /** Indexed, not tokenized, omits norms, indexes
* DOCS_ONLY, not stored. */
public static final FieldType TYPE_NOT_STORED = new FieldType();
/** Indexed, not tokenized, omits norms, indexes
* DOCS_ONLY, stored */
public static final FieldType TYPE_STORED = new FieldType();
该类就不会对存入doc的内容进行语汇分析,这样通过TermQuery q1 = new TermQuery(new Term("title","Lucene in Action"));创建的查询就可以查到“lucene in action”。