`
zhaomengsen
  • 浏览: 198444 次
  • 性别: Icon_minigender_1
  • 来自: 河北
社区版块
存档分类
最新评论

lucene 小例子

阅读更多
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) {

		}
	}

}
本人所说的不规范 。我觉得说的通俗 。使每个人都能理解
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics