我正在尝试学习和理解 lucene 的工作原理,lucene 索引中的内容。基本上我想看看数据是如何在 lucene 索引中表示的?
我lucene-core 8.6.0
用作依赖项
下面是我非常基本的 Lucene 代码
private Document create(File file) throws IOException {
Document document = new Document();
Field field = new Field("contents", new FileReader(file), TextField.TYPE_NOT_STORED);
Field fieldPath = new Field("path", file.getAbsolutePath(), TextField.TYPE_STORED);
Field fieldName = new Field("name", file.getName(), TextField.TYPE_STORED);
document.add(field);
document.add(fieldPath);
document.add(fieldName);
//Create analyzer
Analyzer analyzer = new StandardAnalyzer();
//Create IndexWriter pass the analyzer
Path indexPath = Files.createTempDirectory("tempIndex");
Directory directory = FSDirectory.open(indexPath);
IndexWriterConfig indexWriterCOnfig = new IndexWriterConfig(analyzer);
IndexWriter iwriter = new IndexWriter(directory, indexWriterCOnfig);
iwriter.addDocument(document);
iwriter.close();
return document;
}
注意:我了解 Lucene 背后的知识 - 倒排索引,但我缺乏对 lucene 库使用此概念以及如何创建文件以便使用 lucene 使搜索变得容易和可行的理解。
我试过豪华轿车,但没有用。即使我在 web.xml 中给出了索引位置,它也不起作用