【发布时间】:2016-09-22 09:20:58
【问题描述】:
我想使用 Lucene 6.2.0 版本,我在 java 中创建了两个函数 creatIndex 和 searchIndex 但它没有运行。我不明白如何使用 Field 来参数 Documents 方法。
public void searchIndex(String sentence) throws IOException
{
File dir = new File(INDEX_DIRECTORY);
Path path = dir.toPath();
Directory directory = FSDirectory.open(path);
DirectoryReader ireader=DirectoryReader.open(directory);
IndexSearcher isearcher=new IndexSearcher(ireader);
PhraseQuery.Builder builder = new PhraseQuery.Builder();
String[] words = sentence.split(" ");
for (String word : words) {
builder.add(new Term("contents", word));
}
PhraseQuery pq = builder.build();
TopDocs topDocs = isearcher.search(pq, 10);
for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
Document doc = isearcher.doc(scoreDoc.doc);
System.out.println(doc);
}
}
【问题讨论】:
-
它没有运行,这是错误:在 study_lucense.Study_Lucense.creatDocument(Study_Lucense.java:55) 的 org.apache.lucene.document.Field.
(Field.java:249)在 study_lucense.Study_Lucense.main(Study_Lucense.java:86) -
如果您在问题中添加错误(包括抛出的异常类型,而不是作为注释)会更有帮助。问题底部应该有一个“编辑”链接,您可以将其添加进去。
标签: java lucene information-retrieval