2008
10-8
10-8
- import java.io.*;
- import org.apache.lucene.document.Document;
- import org.apache.lucene.document.Field;
- import org.apache.lucene.index.IndexWriter;
- import org.apache.lucene.analysis.SimpleAnalyzer;
- public class Index
- {
- public static void main( String args[] )
- {
- Document doc = new Document();
- //注释1
- Field f1 = new Field("name1","value1",Field.Store.YES,Field.Index.TOKENIZED);
- Field f2 = new Field("name2","value2",Field.Store.YES,Field.Index.TOKENIZED);
- doc.add( f1 );
- doc.add( f2 );
- try
- {
- IndexWriter writer = new IndexWriter( "./" , new SimpleAnalyzer() , true );
- writer.addDocument( doc );
- writer.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
注释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