Lucene学习笔记--创建FS索引(FSDirectory)

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();
		}
	}
 

相关推荐