lucene6之TextField与StringField对比

来源:互联网 发布:怎么做好网络免费推广 编辑:程序博客网 时间:2024/06/05 11:18

lucene6版本较之最初的版本在字段类型上还是有蛮大区别的,今天重点介绍其中的两个:TextField与StringField,下面直接看源码:

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类:

  /** 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”。



0 0
原创粉丝点击