当我在名为“内容”的字段上使用 PhraseQuery 进行研究时,我收到一个异常。
为了索引这个,我使用了 org.apache.lucene.document.TextField 类,因为这个字段包含很多词。
我使用 FrenchAnalyzerRAMDirectory 类来创建索引。


idxfld = new TextField(field.getFieldname(),(String) field.getValue(),Field.Store.YES);

PhraseQuery query = new PhraseQuery();
query.setSlop(0);
query.add(new Term("comment","the"));
query.add(new Term("comment","skype"));
System.out.println(query.toString());
int numResults = 1000;
ScoreDoc[] hits = searcher.search(query, numResults).scoreDocs;

你能帮助我吗 ?
哔叽

最佳答案

检查您是否使用不同的字段类型索引了相同的字段。

document.Add(new TextField("comment", "Lucene rocks, do you agree?", FieldStore.YES);
.
.
document.Add(new StringField("comment", "Sure", FieldStore.YES);

如果你运行这个短语查询,上面的代码将产生一个“ IllegalStateException field - was indexed without position data ”错误



因此,请确保始终如一地使用 TextField。或者,您也可以使用将 IndexOption 设置为 DOCS_AND_FREQS_AND_POSITIONS 的自定义字段。

关于Lucene 5.2.1 PhraseQuery 被索引没有位置数据无法运行 PhraseQuery,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32781557/

10-11 08:38