欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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();
		}
	}
 
相关标签: lucene

上一篇: 2020-12-05

下一篇: 队列