lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carl...@apache.org
Subject cvs commit: jakarta-lucene-sandbox/contributions/searchbean/src/test/org/apache/lucene TestSearchBean.java
Date Sat, 07 Sep 2002 01:01:01 GMT
carlson     2002/09/06 18:01:01

  Modified:    contributions/searchbean/src/test/org/apache/lucene
                        TestSearchBean.java
  Log:
  I added the Unit Test to include a test on an unoptimized index.
  
  Revision  Changes    Path
  1.2       +36 -11    jakarta-lucene-sandbox/contributions/searchbean/src/test/org/apache/lucene/TestSearchBean.java
  
  Index: TestSearchBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/searchbean/src/test/org/apache/lucene/TestSearchBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestSearchBean.java	21 May 2002 06:29:07 -0000	1.1
  +++ TestSearchBean.java	7 Sep 2002 01:01:01 -0000	1.2
  @@ -58,9 +58,11 @@
   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 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 @@
           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;
       }
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>


Mime
View raw message