Lucene学习笔记--创建FS索引(FSDirectory)
程序员文章站
2022-03-05 12:40:41
...
public void FSDirectoryCreateIndex() {
try {
File file = new File(FILE_PATH);
Directory directory = FSDirectory.getDirectory(INDEX_STORE_PATH);
Document doc = new Document();
IndexWriter indexWriter = new IndexWriter(directory, analyzer,
true, MaxFieldLength.LIMITED);
Field field = new Field("content", loadFileToString(file),
Field.Store.NO, Field.Index.TOKENIZED);
doc.add(field);
field = new Field("name", file.getName(), Field.Store.YES,
Field.Index.TOKENIZED);
doc.add(field);
field = new Field("path", file.getPath(), Field.Store.YES,
Field.Index.TOKENIZED);
doc.add(field);
indexWriter.addDocument(doc);
indexWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
上一篇: 2020-12-05
下一篇: 队列