Apache Lucene open-source search software
I added the Unit Test to include a test on an unoptimized index.
Peter Carlsoncc718580477c
diff --git a/sandbox/contributions/searchbean/src/test/org/apache/lucene/TestSearchBean.java b/sandbox/contributions/searchbean/src/test/org/apache/lucene/TestSearchBean.javaindex 3b57bc9453f..7f4f6fc3ba4 100644--- a/sandbox/contributions/searchbean/src/test/org/apache/lucene/TestSearchBean.java+++ b/sandbox/contributions/searchbean/src/test/org/apache/lucene/TestSearchBean.java@@ -58,9 +58,11 @@ import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.index.Term;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.store.RAMDirectory;+import org.apache.lucene.store.Directory;import org.apache.lucene.analysis.standard.StandardAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;+import org.apache.lucene.index.IndexReader;import org.apache.lucene.queryParser.ParseException;import org.apache.lucene.queryParser.QueryParser;@@ -85,16 +87,7 @@ public class TestSearchBean extends TestCase{**/public void testSearchBean() throws IOException, ParseException {- RAMDirectory indexStore = new RAMDirectory();- IndexWriter writer = new IndexWriter(indexStore, new StandardAnalyzer(), true);- Document doc1 = new Document();- Document doc2 = new Document();- doc1.add(Field.Text("text", "metal"));- doc2.add(Field.Text("text", "metals"));- writer.addDocument(doc1);- writer.addDocument(doc2);- writer.optimize();-+ Directory indexStore = createIndex();SortedField.addField("text",indexStore);//IndexSearcher searcher = new IndexSearcher(indexStore);@@ -102,12 +95,44 @@ public class TestSearchBean extends TestCase{HitsIterator hi = sb.search("metal");assertEquals(1, hi.getTotalHits());-+assertEquals(1, hi.getPageCount());assertEquals("metal",hi.next().get("text"));+ }++ public void testUnoptimizedSearchBean() throws IOException, ParseException {+ Directory indexStore = createIndex();+ IndexReader reader = IndexReader.open(indexStore);+ reader.delete(0);+ //+ reader.close();++ SortedField.addField("text",indexStore);+ //IndexSearcher searcher = new IndexSearcher(indexStore);+ SearchBean sb = new SearchBean(indexStore);+ HitsIterator hi = sb.search("metal");++ assertEquals(0, hi.getTotalHits());++ assertEquals(0, hi.getPageCount());++ //assertEquals("metal",hi.next().get("text"));+ }++ public Directory createIndex() throws IOException{+ RAMDirectory indexStore = new RAMDirectory();+ IndexWriter writer = new IndexWriter(indexStore, new StandardAnalyzer(), true);+ Document doc1 = new Document();+ Document doc2 = new Document();+ doc1.add(Field.Text("text", "metal"));+ doc2.add(Field.Text("text", "metals"));+ writer.addDocument(doc1);+ writer.addDocument(doc2);+ writer.optimize();writer.close();+ return (Directory) indexStore;}}