FileDocCategorySizeDatePackage
TestDocumentWriter.javaAPI DocApache Lucene 1.4.32802Tue Mar 30 00:48:06 BST 2004org.apache.lucene.index

TestDocumentWriter

public class TestDocumentWriter extends TestCase
Copyright 2004 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Fields Summary
private RAMDirectory
dir
private Document
testDoc
Constructors Summary
public TestDocumentWriter(String s)



     
    super(s);
  
Methods Summary
protected voidsetUp()

    DocHelper.setupDoc(testDoc);
  
protected voidtearDown()


  
public voidtest()

    assertTrue(dir != null);

  
public voidtestAddDocument()

    Analyzer analyzer = new WhitespaceAnalyzer();
    Similarity similarity = Similarity.getDefault();
    DocumentWriter writer = new DocumentWriter(dir, analyzer, similarity, 50);
    assertTrue(writer != null);
    try {
      writer.addDocument("test", testDoc);
      //After adding the document, we should be able to read it back in
      SegmentReader reader = new SegmentReader(new SegmentInfo("test", 1, dir));
      assertTrue(reader != null);
      Document doc = reader.document(0);
      assertTrue(doc != null);
      
      //System.out.println("Document: " + doc);
      Field [] fields = doc.getFields("textField2");
      assertTrue(fields != null && fields.length == 1);
      assertTrue(fields[0].stringValue().equals(DocHelper.FIELD_2_TEXT));
      assertTrue(fields[0].isTermVectorStored() == true);
      
      fields = doc.getFields("textField1");
      assertTrue(fields != null && fields.length == 1);
      assertTrue(fields[0].stringValue().equals(DocHelper.FIELD_1_TEXT));
      assertTrue(fields[0].isTermVectorStored() == false);
      
      fields = doc.getFields("keyField");
      assertTrue(fields != null && fields.length == 1);
      assertTrue(fields[0].stringValue().equals(DocHelper.KEYWORD_TEXT));
    } catch (IOException e) {
      e.printStackTrace();
      assertTrue(false);
    }