我正在努力将 Lucene 集成到我们的应用程序中。 Lucene 目前正在工作,例如当我搜索“上传”时,文档中有一些名为“上传”的文本,那么它可以工作,但是当我搜索“Uplo”时,它就不起作用。有任何想法吗?
代码:
Directory directory = FSDirectory.open(path);
IndexReader indexReader = DirectoryReader.open(directory);
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
QueryParser queryParser = new QueryParser("contents", new SimpleAnalyzer());
Query query = queryParser.parse(text);
TopDocs topDocs = indexSearcher.search(query, 50);
for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
org.apache.lucene.document.Document document = indexSearcher.doc(scoreDoc.doc);
objectIds.add(Integer.valueOf(document.get("id")));
System.out.println("");
System.out.println("id " + document.get("id"));
System.out.println("content " + document.get("contents"));
}
return objectIds;
谢谢。
最佳答案
“上传”可能是您的 Lucene 索引中的一个 token ,其中 token 将是不可进一步拆分的最小实体。如果您想匹配“Uplo”这样的部分单词,那么最好选择 Lucene NGram Indexing .请注意,如果您使用 NGram 索引,您将对倒排索引有更高的空间要求。
关于java - 卢塞恩 : Search with partial words,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43756904/