ublic class lucene24 {
@Test
public void create() {
String title = "zhao sen mang";
String content = "zhao sen meng li si wang wu ";
String path = "c:/zhao";\
//创建分词lucene Analyzer 是个接口 ,StandardAnalyzer 是 接口实现类的一种
//自己也可以写分词器
Analyzer analyzer = new StandardAnalyzer();
MaxFieldLength maxFile = MaxFieldLength.LIMITED;
try {
//创建一个索引库的连接
IndexWriter indeWriter = new IndexWriter(path, analyzer, maxFile);
//包索引库放当然要按一定的规则 很像 document 有名称 有
Document document = new Document();
//Field构造方法很多 store 存储内容 index 是检索的内容
document.add(new Field("title", title, Store.YES, Index.ANALYZED));
document.add(new Field("content", content, Store.YES,Index.ANALYZED));
indeWriter.addDocument(document);
indeWriter.close();
} catch (Exception e) {
}
}
}
本人所说的不规范 。我觉得说的通俗 。使每个人都能理解