厚德博学 敬业乐群
@sky
全部博文(252)
2015年(2)
2014年(1)
2013年(1)
2012年(16)
2011年(42)
2010年(67)
2009年(87)
2008年(36)
25742040
shijiulo
niuxlinu
ebayboy
hayand66
大鬼不动
acer1025
醉鬼的故
小雅贝贝
XINGCHEN
wzy_yzw
十的9次
zds05
bjywxc
zlhc1
smile124
cynthia
格伯纳
分类:
2009-08-05 10:30:44
import org.apache.lucene.search.Searcher; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Hits; import org.apache.lucene.search.TermQuery; import org.apache.lucene.document.Document; import org.apache.lucene.index.Term; import org.apache.lucene.search.Query; public class SearchProgram { public static void main(String[] args) throws Exception { IndexSearcher searcher = new IndexSearcher("/root/index"); Term t = new Term("content", "haoyuan"); Query q = new TermQuery(t); Hits hits = searcher.search(q); for (int i = 0; i < hits.length(); i++) { Document doc = hits.doc(i); String str = doc.get("content"); System.out.println(str); } } }
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import java.io.FileReader; public class IndexProgram { public static void main(String[] args) throws Exception { IndexWriter index = new IndexWriter("/root/index", new StandardAnalyzer(), true); Document doc = new Document(); FileReader reader = new FileReader("/root/store/email.txt"); Field field = new Field("content", "haoyuan", Field.Store.YES, Field.Index.ANALYZED); doc.add(field); index.addDocument(doc); index.close(); System.out.println("index /root/store/email.txt success"); } }
上一篇:qt发送邮件测试
下一篇:lucene 分词索引
登录 注册