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(); } }
相关文章推荐
- UVa 11292 The Dragon of Loowater 【贪心】
- UVA11292 The Dragon of Loowater
- uva 11292 The Dragon of Loowater(贪心)
- ACM——The Dragon of Loowater(UVa 11292)
- 例题5-1 UVA 11292 The Dragon of Loowater勇者斗恶龙
- uva11292 The Dragon of Loowater (排序+贪心)
- Uva 11292 The Dragon of Loowater 模拟题
- 勇者斗恶龙(The Dragon of Loowater, UVa 11292)
- uva11292 The Dragon of Loowater (排序+贪心)
- The Dragon of Loowater, UVa 11292
- UVA 11292(p1)----The Dragon of Loowater
- UVa 11292 - The Dragon of Loowater
- Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)
- Uva---11292Problem C: The Dragon of Loowater (贪心)
- 贪心/思维题 UVA 11292 The Dragon of Loowater
- UVa11292_The Dragon of Loowater[java]
- UVA 11292 The Dragon of Loowater(排序问题系列)
- The Dragon of Loowater,UVa 11292
- UVA11292-The Dragon of Loowater
- UVA 11292 The dragon of Loowater勇士斗恶龙 11729 突击战 Commando War