From 965d85f59a2a65d13c24e47962d5d01e02586eb1 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Sun, 30 Oct 2005 05:42:09 +0000 Subject: [PATCH] omitNorms tests, make some tests more generic git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@329526 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/DocHelper.java | 73 ++++++++++++++++--- .../lucene/index/TestDocumentWriter.java | 9 +++ .../apache/lucene/index/TestFieldInfos.java | 18 ++++- .../apache/lucene/index/TestFieldsReader.java | 12 ++- .../apache/lucene/index/TestMultiReader.java | 5 +- .../lucene/index/TestSegmentMerger.java | 8 +- .../lucene/index/TestSegmentReader.java | 50 ++++++++++--- 7 files changed, 145 insertions(+), 30 deletions(-) diff --git a/src/test/org/apache/lucene/index/DocHelper.java b/src/test/org/apache/lucene/index/DocHelper.java index 9620e23ebca..2d1de60b8dc 100644 --- a/src/test/org/apache/lucene/index/DocHelper.java +++ b/src/test/org/apache/lucene/index/DocHelper.java @@ -36,17 +36,28 @@ class DocHelper { public static final int [] FIELD_2_FREQS = {3, 1, 1}; public static final String TEXT_FIELD_2_KEY = "textField2"; public static Field textField2 = new Field(TEXT_FIELD_2_KEY, FIELD_2_TEXT, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS); - + + public static final String FIELD_3_TEXT = "aaaNoNorms aaaNoNorms bbbNoNorms"; + public static final String TEXT_FIELD_3_KEY = "textField3"; + public static Field textField3 = new Field(TEXT_FIELD_3_KEY, FIELD_3_TEXT, Field.Store.YES, Field.Index.TOKENIZED); + static { textField3.setOmitNorms(true); } + public static final String KEYWORD_TEXT = "Keyword"; public static final String KEYWORD_FIELD_KEY = "keyField"; public static Field keyField = new Field(KEYWORD_FIELD_KEY, KEYWORD_TEXT, Field.Store.YES, Field.Index.UN_TOKENIZED); - + + public static final String NO_NORMS_TEXT = "omitNormsText"; + public static final String NO_NORMS_KEY = "omitNorms"; + public static Field noNormsField = new Field(NO_NORMS_KEY, NO_NORMS_TEXT, + Field.Store.YES, Field.Index.NO_NORMS); + public static final String UNINDEXED_FIELD_TEXT = "unindexed field text"; public static final String UNINDEXED_FIELD_KEY = "unIndField"; public static Field unIndField = new Field(UNINDEXED_FIELD_KEY, UNINDEXED_FIELD_TEXT, Field.Store.YES, Field.Index.NO); - + + public static final String UNSTORED_1_FIELD_TEXT = "unstored field text"; public static final String UNSTORED_FIELD_1_KEY = "unStoredField1"; public static Field unStoredField1 = new Field(UNSTORED_FIELD_1_KEY, UNSTORED_1_FIELD_TEXT, @@ -58,13 +69,58 @@ class DocHelper { Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.YES); public static Map nameValues = null; - + + // ordered list of all the fields... + // could use LinkedHashMap for this purpose if Java1.4 is OK + public static Field[] fields = new Field[] { + textField1, + textField2, + textField3, + keyField, + noNormsField, + unIndField, + unStoredField1, + unStoredField2, + }; + + // Map + public static Map all=new HashMap(); + public static Map indexed=new HashMap(); + public static Map stored=new HashMap(); + public static Map unstored=new HashMap(); + public static Map unindexed=new HashMap(); + public static Map termvector=new HashMap(); + public static Map notermvector=new HashMap(); + public static Map noNorms=new HashMap(); + + static { + for (int i=0; i 0); - assertTrue(DocHelper.numFields(testDoc) == 6); + assertTrue(DocHelper.numFields(testDoc) == DocHelper.all.size()); } public void testDocument() throws IOException { @@ -59,7 +60,7 @@ public class TestSegmentReader extends TestCase { Document result = reader.document(0); assertTrue(result != null); //There are 2 unstored fields on the document that are not preserved across writing - assertTrue(DocHelper.numFields(result) == DocHelper.numFields(testDoc) - 2); + assertTrue(DocHelper.numFields(result) == DocHelper.numFields(testDoc) - DocHelper.unstored.size()); Enumeration fields = result.fields(); while (fields.hasMoreElements()) { @@ -91,7 +92,7 @@ public class TestSegmentReader extends TestCase { public void testGetFieldNameVariations() { Collection result = reader.getFieldNames(IndexReader.FieldOption.ALL); assertTrue(result != null); - assertTrue(result.size() == 6); + assertTrue(result.size() == DocHelper.all.size()); for (Iterator iter = result.iterator(); iter.hasNext();) { String s = (String) iter.next(); //System.out.println("Name: " + s); @@ -99,23 +100,23 @@ public class TestSegmentReader extends TestCase { } result = reader.getFieldNames(IndexReader.FieldOption.INDEXED); assertTrue(result != null); - assertTrue(result.size() == 5); + assertTrue(result.size() == DocHelper.indexed.size()); for (Iterator iter = result.iterator(); iter.hasNext();) { String s = (String) iter.next(); - assertTrue(DocHelper.nameValues.containsKey(s) == true || s.equals("")); + assertTrue(DocHelper.indexed.containsKey(s) == true || s.equals("")); } result = reader.getFieldNames(IndexReader.FieldOption.UNINDEXED); assertTrue(result != null); - assertTrue(result.size() == 1); + assertTrue(result.size() == DocHelper.unindexed.size()); //Get all indexed fields that are storing term vectors result = reader.getFieldNames(IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR); assertTrue(result != null); - assertTrue(result.size() == 2); + assertTrue(result.size() == DocHelper.termvector.size()); result = reader.getFieldNames(IndexReader.FieldOption.INDEXED_NO_TERMVECTOR); assertTrue(result != null); - assertTrue(result.size() == 3); + assertTrue(result.size() == DocHelper.notermvector.size()); } public void testTerms() throws IOException { @@ -134,6 +135,10 @@ public class TestSegmentReader extends TestCase { assertTrue(termDocs != null); termDocs.seek(new Term(DocHelper.TEXT_FIELD_1_KEY, "field")); assertTrue(termDocs.next() == true); + + termDocs.seek(new Term(DocHelper.NO_NORMS_KEY, DocHelper.NO_NORMS_TEXT)); + assertTrue(termDocs.next() == true); + TermPositions positions = reader.termPositions(); positions.seek(new Term(DocHelper.TEXT_FIELD_1_KEY, "field")); @@ -142,7 +147,7 @@ public class TestSegmentReader extends TestCase { assertTrue(positions.nextPosition() >= 0); } - public void testNorms() { + public void testNorms() throws IOException { //TODO: Not sure how these work/should be tested /* try { @@ -155,7 +160,32 @@ public class TestSegmentReader extends TestCase { } */ - } + checkNorms(reader); + } + + public static void checkNorms(IndexReader reader) throws IOException { + // test omit norms + for (int i=0; i