我在名爲'content'的字段對PhraseQuery
進行研究時收到異常。
要索引這一個,我使用org.apache.lucene.document.TextField
類,因爲這個字段包含很多單詞。
我使用FrenchAnalyzer
和RAMDirectory
類來創建索引。Lucene 5.2.1 PhraseQuery無位置數據索引無法運行PhraseQuery
線程「main」中的異常java.lang.IllegalStateException:字段「comment」被索引而沒有位置數據;無法在org.apache.lucene.search.PhraseQuery上運行PhraseQuery(phrase = comment:「the skype」) org.apache.lucene.search.Weight.bulkScorer(重量.java:137) at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:768) at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:485) at org.apache .rocene.search.IndexSearcher.search(IndexSearcher.java:694) at org.apache.lucene.search.IndexSearcher.searchAfter(IndexSearcher.java:410) at org.apache.lucene.search.IndexSearcher.search(IndexSearcher .java:439) at org.memory.LuceneIndexer.wildcardSearchIndex(LuceneIndexer.java:189) at org.memory.Mem_04.main(Mem_04.java:60)
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;
你能幫我嗎? Serge