您的位置:首页 > 编程语言 > Go语言

UVA11292 The Dragon of Loowater

2013-07-15 21:05 405 查看
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.RAMDirectory;

import junit.framework.TestCase;

public class testDirectory extends TestCase {

String path = "./index";

public void test() throws Exception {

Directory fsDir = FSDirectory.getDirectory(path);
Directory ramDir = new RAMDirectory();
IndexWriter ramWrite = new IndexWriter(ramDir, new StandardAnalyzer(),
true, IndexWriter.MaxFieldLength.UNLIMITED);
IndexWriter fsWrite = new IndexWriter(fsDir, new StandardAnalyzer(),
true, IndexWriter.MaxFieldLength.UNLIMITED);

// 可以把一批建立索引的操作在内存中进行,避免频繁的IO操作建立索引
Document doc = new Document();
doc.add(new Field("id", "001", Field.Store.YES,
Field.Index.NOT_ANALYZED));
doc.add(new Field("content", "what are you doning", Field.Store.NO,
Field.Index.ANALYZED));
ramWrite.addDocument(doc);
// 必须要先关闭才能调用addIndexesNoOptimize方法把ramDir参数传入
ramWrite.close();
// 调用addIndexesNoOptimize方法把索引加到IndexWriter
fsWrite.addIndexesNoOptimize(new Directory[] { ramDir });
// 最后不要忘记关闭IndexWriter释放write.lock,把索引写入磁盘
fsWrite.close();

}
}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: