Lucene创建Document代码部分-循序渐进学Lucene

作者 : admin 于 2008-10-08 18:47:49 标签: ,
2008
10-8
  1. import java.io.*;
  2. import org.apache.lucene.document.Document;
  3. import org.apache.lucene.document.Field;
  4. import org.apache.lucene.index.IndexWriter;
  5. import org.apache.lucene.analysis.SimpleAnalyzer;
  6. public class Index
  7. {
  8. public static void main( String args[] )
  9. {
  10. Document doc = new Document();
  11. //注释1
  12. Field f1 = new Field("name1","value1",Field.Store.YES,Field.Index.TOKENIZED);
  13. Field f2 = new Field("name2","value2",Field.Store.YES,Field.Index.TOKENIZED);
  14. doc.add( f1 );
  15. doc.add( f2 );
  16. try
  17. {
  18. IndexWriter writer = new IndexWriter( "./" , new SimpleAnalyzer() , true );
  19. writer.addDocument( doc );
  20. writer.close();
  21. }
  22. catch (Exception e)
  23. {
  24.                        e.printStackTrace();
  25. }
  26. }
  27. }

注释1:Field方法的在2.0.0版本中有5种方法,在2.3.2中增加到了7种,详细用法请参阅官方文档
http://lucene.apache.org/java/2_0_0/api/org/apache/lucene/document/Field.html
http://lucene.apache.org/java/2_3_2/api/org/apache/lucene/document/Field.html

发表评论




XHTML:你可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(若看不到验证码,请重新加载页面。)