lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bmes...@apache.org
Subject cvs commit: jakarta-lucene/src/test/org/apache/lucene/index TestSegmentReader.java TestIndexReader.java TestSegmentMerger.java
Date Wed, 29 Dec 2004 21:38:41 GMT
bmesser     2004/12/29 13:38:41

  Modified:    src/test/org/apache/lucene/index TestSegmentReader.java
                        TestIndexReader.java TestSegmentMerger.java
  Log:
  adjust test cases to make use of the new IndexReader.getFieldNames method
  
  Revision  Changes    Path
  1.7       +5 -5      jakarta-lucene/src/test/org/apache/lucene/index/TestSegmentReader.java
  
  Index: TestSegmentReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/index/TestSegmentReader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestSegmentReader.java	19 Dec 2004 14:58:49 -0000	1.6
  +++ TestSegmentReader.java	29 Dec 2004 21:38:41 -0000	1.7
  @@ -104,7 +104,7 @@
     }    
     
     public void testGetFieldNameVariations() {
  -    Collection result = reader.getFieldNames();
  +    Collection result = reader.getFieldNames(IndexReader.FieldOption.ALL);
       assertTrue(result != null);
       assertTrue(result.size() == 6);
       for (Iterator iter = result.iterator(); iter.hasNext();) {
  @@ -112,7 +112,7 @@
         //System.out.println("Name: " + s);
         assertTrue(DocHelper.nameValues.containsKey(s) == true || s.equals(""));
       }                                                                               
  -    result = reader.getFieldNames(true);
  +    result = reader.getFieldNames(IndexReader.FieldOption.INDEXED);
       assertTrue(result != null);
       assertTrue(result.size() == 5);
       for (Iterator iter = result.iterator(); iter.hasNext();) {
  @@ -120,15 +120,15 @@
         assertTrue(DocHelper.nameValues.containsKey(s) == true || s.equals(""));
       }
       
  -    result = reader.getFieldNames(false);
  +    result = reader.getFieldNames(IndexReader.FieldOption.UNINDEXED);
       assertTrue(result != null);
       assertTrue(result.size() == 1);
       //Get all indexed fields that are storing term vectors
  -    result = reader.getIndexedFieldNames(true);
  +    result = reader.getFieldNames(IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR);
       assertTrue(result != null);
       assertTrue(result.size() == 2);
       
  -    result = reader.getIndexedFieldNames(false);
  +    result = reader.getFieldNames(IndexReader.FieldOption.INDEXED_NO_TERMVECTOR);
       assertTrue(result != null);
       assertTrue(result.size() == 3);
     } 
  
  
  
  1.12      +63 -17    jakarta-lucene/src/test/org/apache/lucene/index/TestIndexReader.java
  
  Index: TestIndexReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/index/TestIndexReader.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TestIndexReader.java	22 Dec 2004 19:43:05 -0000	1.11
  +++ TestIndexReader.java	29 Dec 2004 21:38:41 -0000	1.12
  @@ -62,7 +62,7 @@
           writer.close();
           // set up reader
           IndexReader reader = IndexReader.open(d);
  -        Collection fieldNames = reader.getFieldNames();
  +        Collection fieldNames = reader.getFieldNames(IndexReader.FieldOption.ALL);
           assertTrue(fieldNames.contains("keyword"));
           assertTrue(fieldNames.contains("text"));
           assertTrue(fieldNames.contains("unindexed"));
  @@ -79,11 +79,17 @@
           {
               addDocumentWithDifferentFields(writer);
           }
  +        // new termvector fields
  +        for (int i = 0; i < 5*writer.getMergeFactor(); i++)
  +        {
  +          addDocumentWithTermVectorFields(writer);
  +        }
  +        
           writer.close();
           // verify fields again
           reader = IndexReader.open(d);
  -        fieldNames = reader.getFieldNames();
  -        assertEquals(8, fieldNames.size());    // the following fields
  +        fieldNames = reader.getFieldNames(IndexReader.FieldOption.ALL);
  +        assertEquals(13, fieldNames.size());    // the following fields
           assertTrue(fieldNames.contains("keyword"));
           assertTrue(fieldNames.contains("text"));
           assertTrue(fieldNames.contains("unindexed"));
  @@ -92,22 +98,50 @@
           assertTrue(fieldNames.contains("text2"));
           assertTrue(fieldNames.contains("unindexed2"));
           assertTrue(fieldNames.contains("unstored2"));
  -
  +        assertTrue(fieldNames.contains("tvnot"));
  +        assertTrue(fieldNames.contains("termvector"));
  +        assertTrue(fieldNames.contains("tvposition"));
  +        assertTrue(fieldNames.contains("tvoffset"));
  +        assertTrue(fieldNames.contains("tvpositionoffset"));
  +        
           // verify that only indexed fields were returned
  -        Collection indexedFieldNames = reader.getFieldNames(true);
  -        assertEquals(6, indexedFieldNames.size());
  -        assertTrue(indexedFieldNames.contains("keyword"));
  -        assertTrue(indexedFieldNames.contains("text"));
  -        assertTrue(indexedFieldNames.contains("unstored"));
  -        assertTrue(indexedFieldNames.contains("keyword2"));
  -        assertTrue(indexedFieldNames.contains("text2"));
  -        assertTrue(indexedFieldNames.contains("unstored2"));
  -
  +        fieldNames = reader.getFieldNames(IndexReader.FieldOption.INDEXED);
  +        assertEquals(11, fieldNames.size());    // 6 original + the 5 termvector fields

  +        assertTrue(fieldNames.contains("keyword"));
  +        assertTrue(fieldNames.contains("text"));
  +        assertTrue(fieldNames.contains("unstored"));
  +        assertTrue(fieldNames.contains("keyword2"));
  +        assertTrue(fieldNames.contains("text2"));
  +        assertTrue(fieldNames.contains("unstored2"));
  +        assertTrue(fieldNames.contains("tvnot"));
  +        assertTrue(fieldNames.contains("termvector"));
  +        assertTrue(fieldNames.contains("tvposition"));
  +        assertTrue(fieldNames.contains("tvoffset"));
  +        assertTrue(fieldNames.contains("tvpositionoffset"));
  +        
           // verify that only unindexed fields were returned
  -        Collection unindexedFieldNames = reader.getFieldNames(false);
  -        assertEquals(2, unindexedFieldNames.size());    // the following fields
  -        assertTrue(unindexedFieldNames.contains("unindexed"));
  -        assertTrue(unindexedFieldNames.contains("unindexed2"));
  +        fieldNames = reader.getFieldNames(IndexReader.FieldOption.UNINDEXED);
  +        assertEquals(2, fieldNames.size());    // the following fields
  +        assertTrue(fieldNames.contains("unindexed"));
  +        assertTrue(fieldNames.contains("unindexed2"));
  +                
  +        // verify index term vector fields  
  +        fieldNames = reader.getFieldNames(IndexReader.FieldOption.TERMVECTOR);
  +        assertEquals(1, fieldNames.size());    // 1 field has term vector only
  +        assertTrue(fieldNames.contains("termvector"));
  +        
  +        fieldNames = reader.getFieldNames(IndexReader.FieldOption.TERMVECTOR_WITH_POSITION);
  +        assertEquals(1, fieldNames.size());    // 4 fields are indexed with term vectors
  +        assertTrue(fieldNames.contains("tvposition"));
  +        
  +        fieldNames = reader.getFieldNames(IndexReader.FieldOption.TERMVECTOR_WITH_OFFSET);
  +        assertEquals(1, fieldNames.size());    // 4 fields are indexed with term vectors
  +        assertTrue(fieldNames.contains("tvoffset"));
  +                
  +        fieldNames = reader.getFieldNames(IndexReader.FieldOption.TERMVECTOR_WITH_POSITION_OFFSET);
  +        assertEquals(1, fieldNames.size());    // 4 fields are indexed with term vectors
  +        assertTrue(fieldNames.contains("tvpositionoffset"));
  +        
       }
   
   
  @@ -431,6 +465,18 @@
           writer.addDocument(doc);
       }
   
  +    private void addDocumentWithTermVectorFields(IndexWriter writer) throws IOException
  +    {
  +        Document doc = new Document();
  +        doc.add(new Field("tvnot","tvnot", Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
  +        doc.add(new Field("termvector","termvector", Field.Store.YES, Field.Index.TOKENIZED,
Field.TermVector.YES));
  +        doc.add(new Field("tvoffset","tvoffset", Field.Store.YES, Field.Index.TOKENIZED,
Field.TermVector.WITH_OFFSETS));
  +        doc.add(new Field("tvposition","tvposition", Field.Store.YES, Field.Index.TOKENIZED,
Field.TermVector.WITH_POSITIONS));
  +        doc.add(new Field("tvpositionoffset","tvpositionoffset", Field.Store.YES, Field.Index.TOKENIZED,
Field.TermVector.WITH_POSITIONS_OFFSETS));
  +        
  +        writer.addDocument(doc);
  +    }
  +    
       private void addDoc(IndexWriter writer, String value)
       {
           Document doc = new Document();
  
  
  
  1.7       +2 -2      jakarta-lucene/src/test/org/apache/lucene/index/TestSegmentMerger.java
  
  Index: TestSegmentMerger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/index/TestSegmentMerger.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestSegmentMerger.java	5 Oct 2004 17:30:47 -0000	1.6
  +++ TestSegmentMerger.java	29 Dec 2004 21:38:41 -0000	1.7
  @@ -95,9 +95,9 @@
         assertTrue(termDocs != null);
         assertTrue(termDocs.next() == true);
         
  -      Collection stored = mergedReader.getIndexedFieldNames(true);
  +      Collection stored = mergedReader.getFieldNames(IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR);
         assertTrue(stored != null);
  -      //System.out.println("stored size: " + stored.size());
  +      System.out.println("stored size: " + stored.size());
         assertTrue(stored.size() == 2);
         
         TermFreqVector vector = mergedReader.getTermFreqVector(0, DocHelper.TEXT_FIELD_2_KEY);
  
  
  

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


Mime
View raw message