Field類是文檔索引期間很重要的類,控制着被索引的域值。html
在作phrasequery查詢的時候,報出了這樣一個錯誤:java
Exception in thread "main" java.lang.IllegalStateException: field "content" was indexed without position data; cannot run PhraseQuery (term=lymphoid)apache
Goolgle下,有前輩說多是 field index option設置的問題,這裏贊一下外國IT社區的技術大牛們,給的解答都很詳細。spa
因而查詢Lucene手冊,首先查到FieldType類code
setIndexOptions(FieldInfo.IndexOptions value)
orm
Sets the indexing options for the field:htm
繼續查找FieldInfo.IndexOptions,發現了索引
public static final FieldInfo.IndexOptions DOCS_AND_FREQS
Only documents and term frequencies are indexed: positions are omitted. This enables normal scoring, except Phrase and other positional queries will throw an exception.ci
注意positions are omitted這句,恰好以前設置了文檔
setIndexOptions(FieldInfo.IndexOptions.DOCS_AND_FREQS), 加上位置
setIndexOptions(FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS),問題解決。