FileDocCategorySizeDatePackage
TestTermVectorsReader.javaAPI DocApache Lucene 1.93150Mon Feb 20 09:20:32 GMT 2006org.apache.lucene.index

TestTermVectorsReader

public class TestTermVectorsReader extends TestCase

Fields Summary
private TermVectorsWriter
writer
private String[]
testFields
private String[]
testTerms
private RAMDirectory
dir
private String
seg
private FieldInfos
fieldInfos
Constructors Summary
public TestTermVectorsReader(String s)


     
    super(s);
  
Methods Summary
protected voidsetUp()

    for (int i = 0; i < testFields.length; i++) {
      fieldInfos.add(testFields[i], true, true);
    }
    
    try {
      Arrays.sort(testTerms);
      for (int j = 0; j < 5; j++) {
        writer = new TermVectorsWriter(dir, seg, fieldInfos);
        writer.openDocument();

        for (int k = 0; k < testFields.length; k++) {
          writer.openField(testFields[k]);
          for (int i = 0; i < testTerms.length; i++) {
            writer.addTerm(testTerms[i], i);      
          }
          writer.closeField();
        }
        writer.closeDocument();
        writer.close();
      }

    } catch (IOException e) {
      e.printStackTrace();
      assertTrue(false);
    }    
  
protected voidtearDown()


  
public voidtest()

      //Check to see the files were created properly in setup
      assertTrue(writer.isDocumentOpen() == false);          
      assertTrue(dir.fileExists(seg + TermVectorsWriter.TVD_EXTENSION));
      assertTrue(dir.fileExists(seg + TermVectorsWriter.TVX_EXTENSION));
  
public voidtestBadParams()
Make sure exceptions and bad params are handled appropriately

    try {
      TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
      assertTrue(reader != null);
      //Bad document number, good field number
      TermFreqVector vector = reader.get(50, testFields[0]);
      assertTrue(false);      
    } catch (IOException e) {
      assertTrue(true);
    }
    try {
      TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
      assertTrue(reader != null);
      //good document number, bad field number
      TermFreqVector vector = reader.get(0, "f50");
      assertTrue(vector == null);      
    } catch (IOException e) {
      assertTrue(false);
    }
  
public voidtestReader()

    try {
      TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
      assertTrue(reader != null);
      TermFreqVector vector = reader.get(0, testFields[0]);
      assertTrue(vector != null);
      String [] terms = vector.getTerms();
      assertTrue(terms != null);
      assertTrue(terms.length == testTerms.length);
      for (int i = 0; i < terms.length; i++) {
        String term = terms[i];
        //System.out.println("Term: " + term);
        assertTrue(term.equals(testTerms[i]));
      }
      
    } catch (IOException e) {
      e.printStackTrace();
      assertTrue(false);
    }