1 package org.apache.lucene.index; 2 3 18 19 import junit.framework.TestCase; 20 import org.apache.lucene.store.RAMDirectory; 21 import org.apache.lucene.document.Document; 22 import org.apache.lucene.document.Field; 23 import org.apache.lucene.analysis.WhitespaceAnalyzer; 24 import org.apache.lucene.search.Similarity; 25 26 import java.util.Map ; 27 import java.io.IOException ; 28 29 public class TestFieldsReader extends TestCase { 30 private RAMDirectory dir = new RAMDirectory(); 31 private Document testDoc = new Document(); 32 private FieldInfos fieldInfos = null; 33 34 public TestFieldsReader(String s) { 35 super(s); 36 } 37 38 protected void setUp() { 39 fieldInfos = new FieldInfos(); 40 DocHelper.setupDoc(testDoc); 41 fieldInfos.add(testDoc); 42 DocumentWriter writer = new DocumentWriter(dir, new WhitespaceAnalyzer(), 43 Similarity.getDefault(), 50); 44 assertTrue(writer != null); 45 try { 46 writer.addDocument("test", testDoc); 47 } 48 catch (IOException e) 49 { 50 51 } 52 } 53 54 protected void tearDown() { 55 56 } 57 58 public void test() { 59 assertTrue(dir != null); 60 assertTrue(fieldInfos != null); 61 try { 62 FieldsReader reader = new FieldsReader(dir, "test", fieldInfos); 63 assertTrue(reader != null); 64 assertTrue(reader.size() == 1); 65 Document doc = reader.doc(0); 66 assertTrue(doc != null); 67 assertTrue(doc.getField("textField1") != null); 68 Field field = doc.getField("textField2"); 69 assertTrue(field != null); 70 assertTrue(field.isTermVectorStored() == true); 71 reader.close(); 72 } catch (IOException e) { 73 e.printStackTrace(); 74 assertTrue(false); 75 } 76 } 77 } 78 | Popular Tags |