简单的建立索引:
public static void main(String[] args)throws Exception{
String [] ids={"1","2","3"};
String [] names={"heh","btb","ee"};
String [] addr={"bupt","thu","sjtu"};
Analyzer analyzer=new StandardAnalyzer();
String index="D:/Users/huaiyu/Workspaces/luenceindex";
Directory dir=FSDirectory.getDirectory(index);
IndexWriter writer=new IndexWriter(dir,analyzer,true,IndexWriter.MaxFieldLength.LIMITED);
for(int i=0;i<ids.length;i++){
org.apache.lucene.document.Document doc=new org.apache.lucene.document.Document();
doc.add(new org.apache.lucene.document.Field("id",ids[i],org.apache.lucene.document.Field.Store.YES,org.apache.lucene.document.Field.Index.ANALYZED));
doc.add(new org.apache.lucene.document.Field("name",names[i],org.apache.lucene.document.Field.Store.NO,org.apache.lucene.document.Field.Index.ANALYZED));
doc.add(new org.apache.lucene.document.Field("addr",addr[i],org.apache.lucene.document.Field.Store.YES,org.apache.lucene.document.Field.Index.ANALYZED));
writer.addDocument(doc);
}
writer.optimize();
writer.close();
}
reference source:
1: lucene3:index build and term delete
2:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece763104c8c711923d030678197027fa3c215cc79021c1b33a9e0747e455e84c67c661cf40f0bb5ed3770635020bc919cde4edcec907b288e2731274cd04a46d30dea960673ce7ed70bbef34ef0ba816ac0ea81c4df2553dd52756d80879c5b7012dd6e80033194b19838164810cbfa4116e8297c3ee92257c746eee1427976f1e1a9595bb52ac71567&p=98708b0396d212a05abd9b7e0d108a&newp=8b2a971fc58819ff57ed9478444789231610db2151d0da1f25c7d810&user=baidu&fm=sc&query=lucene+java+2%2E4%2E1+%CA%B9%D3%C3%CB%F7%D2%FD&qid=&p1=3