You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2011/08/27 15:27:12 UTC
svn commit: r1162347 [7/15] - in /lucene/dev/trunk: lucene/ lucene/contrib/
lucene/contrib/demo/src/java/org/apache/lucene/demo/
lucene/contrib/demo/src/java/org/apache/lucene/demo/xmlparser/
lucene/contrib/highlighter/src/java/org/apache/lucene/search...
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java?rev=1162347&r1=1162346&r2=1162347&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java Sat Aug 27 13:27:01 2011
@@ -25,15 +25,9 @@ import org.apache.lucene.analysis.MockAn
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericField;
-import org.apache.lucene.document.FieldSelector;
-import org.apache.lucene.document.FieldSelectorResult;
-import org.apache.lucene.document.Fieldable;
-import org.apache.lucene.document.LoadFirstFieldSelector;
-import org.apache.lucene.document.SetBasedFieldSelector;
import org.apache.lucene.index.FieldInfo.IndexOptions;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.search.FieldCache;
-import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.BufferedIndexInput;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
@@ -48,7 +42,6 @@ public class TestFieldsReader extends Lu
private static Directory dir;
private static Document testDoc = new Document();
private static FieldInfos fieldInfos = null;
- private final static String TEST_SEGMENT_NAME = "_0";
@BeforeClass
public static void beforeClass() throws Exception {
@@ -61,14 +54,9 @@ public class TestFieldsReader extends Lu
IndexWriter writer = new IndexWriter(dir, conf);
writer.addDocument(testDoc);
writer.close();
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
FaultyIndexInput.doFail = false;
}
-
+
@AfterClass
public static void afterClass() throws Exception {
dir.close();
@@ -76,325 +64,48 @@ public class TestFieldsReader extends Lu
fieldInfos = null;
testDoc = null;
}
+
public void test() throws IOException {
assertTrue(dir != null);
assertTrue(fieldInfos != null);
- FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
- assertTrue(reader.size() == 1);
- Document doc = reader.doc(0, null);
+ IndexReader reader = IndexReader.open(dir);
+ Document doc = reader.document(0);
assertTrue(doc != null);
assertTrue(doc.getField(DocHelper.TEXT_FIELD_1_KEY) != null);
- Fieldable field = doc.getField(DocHelper.TEXT_FIELD_2_KEY);
+ Field field = (Field) doc.getField(DocHelper.TEXT_FIELD_2_KEY);
assertTrue(field != null);
- assertTrue(field.isTermVectorStored() == true);
+ assertTrue(field.storeTermVectors() == true);
- assertTrue(field.isStoreOffsetWithTermVector() == true);
- assertTrue(field.isStorePositionWithTermVector() == true);
- assertTrue(field.getOmitNorms() == false);
- assertTrue(field.getIndexOptions() == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
+ assertTrue(field.storeTermVectorOffsets() == true);
+ assertTrue(field.storeTermVectorPositions() == true);
+ assertTrue(field.omitNorms() == false);
+ assertTrue(field.indexOptions() == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
- field = doc.getField(DocHelper.TEXT_FIELD_3_KEY);
+ field = (Field) doc.getField(DocHelper.TEXT_FIELD_3_KEY);
assertTrue(field != null);
- assertTrue(field.isTermVectorStored() == false);
- assertTrue(field.isStoreOffsetWithTermVector() == false);
- assertTrue(field.isStorePositionWithTermVector() == false);
- assertTrue(field.getOmitNorms() == true);
- assertTrue(field.getIndexOptions() == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
+ assertTrue(field.storeTermVectors() == false);
+ assertTrue(field.storeTermVectorOffsets() == false);
+ assertTrue(field.storeTermVectorPositions() == false);
+ assertTrue(field.omitNorms() == true);
+ assertTrue(field.indexOptions() == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
- field = doc.getField(DocHelper.NO_TF_KEY);
+ field = (Field) doc.getField(DocHelper.NO_TF_KEY);
assertTrue(field != null);
- assertTrue(field.isTermVectorStored() == false);
- assertTrue(field.isStoreOffsetWithTermVector() == false);
- assertTrue(field.isStorePositionWithTermVector() == false);
- assertTrue(field.getOmitNorms() == false);
- assertTrue(field.getIndexOptions() == IndexOptions.DOCS_ONLY);
- reader.close();
- }
-
-
- public void testLazyFields() throws Exception {
- assertTrue(dir != null);
- assertTrue(fieldInfos != null);
- FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
- assertTrue(reader.size() == 1);
- Set<String> loadFieldNames = new HashSet<String>();
- loadFieldNames.add(DocHelper.TEXT_FIELD_1_KEY);
- loadFieldNames.add(DocHelper.TEXT_FIELD_UTF1_KEY);
- Set<String> lazyFieldNames = new HashSet<String>();
- //new String[]{DocHelper.LARGE_LAZY_FIELD_KEY, DocHelper.LAZY_FIELD_KEY, DocHelper.LAZY_FIELD_BINARY_KEY};
- lazyFieldNames.add(DocHelper.LARGE_LAZY_FIELD_KEY);
- lazyFieldNames.add(DocHelper.LAZY_FIELD_KEY);
- lazyFieldNames.add(DocHelper.LAZY_FIELD_BINARY_KEY);
- lazyFieldNames.add(DocHelper.TEXT_FIELD_UTF2_KEY);
- SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(loadFieldNames, lazyFieldNames);
- Document doc = reader.doc(0, fieldSelector);
- assertTrue("doc is null and it shouldn't be", doc != null);
- Fieldable field = doc.getFieldable(DocHelper.LAZY_FIELD_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("field is not lazy and it should be", field.isLazy());
- String value = field.stringValue();
- assertTrue("value is null and it shouldn't be", value != null);
- assertTrue(value + " is not equal to " + DocHelper.LAZY_FIELD_TEXT, value.equals(DocHelper.LAZY_FIELD_TEXT) == true);
- assertTrue("calling stringValue() twice should give same reference", field.stringValue() == field.stringValue());
-
- field = doc.getFieldable(DocHelper.TEXT_FIELD_1_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("Field is lazy and it should not be", field.isLazy() == false);
- field = doc.getFieldable(DocHelper.TEXT_FIELD_UTF1_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("Field is lazy and it should not be", field.isLazy() == false);
- assertTrue(field.stringValue() + " is not equal to " + DocHelper.FIELD_UTF1_TEXT, field.stringValue().equals(DocHelper.FIELD_UTF1_TEXT) == true);
-
- field = doc.getFieldable(DocHelper.TEXT_FIELD_UTF2_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("Field is lazy and it should not be", field.isLazy() == true);
- assertTrue(field.stringValue() + " is not equal to " + DocHelper.FIELD_UTF2_TEXT, field.stringValue().equals(DocHelper.FIELD_UTF2_TEXT) == true);
-
- field = doc.getFieldable(DocHelper.LAZY_FIELD_BINARY_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("stringValue isn't null for lazy binary field", field.stringValue() == null);
-
- byte [] bytes = field.getBinaryValue();
- assertTrue("bytes is null and it shouldn't be", bytes != null);
- assertTrue("", DocHelper.LAZY_FIELD_BINARY_BYTES.length == bytes.length);
- assertTrue("calling binaryValue() twice should give same reference", field.getBinaryValue() == field.getBinaryValue());
- for (int i = 0; i < bytes.length; i++) {
- assertTrue("byte[" + i + "] is mismatched", bytes[i] == DocHelper.LAZY_FIELD_BINARY_BYTES[i]);
-
- }
- reader.close();
- }
-
- public void testLatentFields() throws Exception {
- assertTrue(dir != null);
- assertTrue(fieldInfos != null);
- FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
- assertTrue(reader.size() == 1);
- Set<String> loadFieldNames = new HashSet<String>();
- loadFieldNames.add(DocHelper.TEXT_FIELD_1_KEY);
- loadFieldNames.add(DocHelper.TEXT_FIELD_UTF1_KEY);
- Set<String> lazyFieldNames = new HashSet<String>();
- //new String[]{DocHelper.LARGE_LAZY_FIELD_KEY, DocHelper.LAZY_FIELD_KEY, DocHelper.LAZY_FIELD_BINARY_KEY};
- lazyFieldNames.add(DocHelper.LARGE_LAZY_FIELD_KEY);
- lazyFieldNames.add(DocHelper.LAZY_FIELD_KEY);
- lazyFieldNames.add(DocHelper.LAZY_FIELD_BINARY_KEY);
- lazyFieldNames.add(DocHelper.TEXT_FIELD_UTF2_KEY);
-
- // Use LATENT instead of LAZY
- SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(loadFieldNames, lazyFieldNames) {
- @Override
- public FieldSelectorResult accept(String fieldName) {
- final FieldSelectorResult result = super.accept(fieldName);
- if (result == FieldSelectorResult.LAZY_LOAD) {
- return FieldSelectorResult.LATENT;
- } else {
- return result;
- }
- }
- };
-
- Document doc = reader.doc(0, fieldSelector);
- assertTrue("doc is null and it shouldn't be", doc != null);
- Fieldable field = doc.getFieldable(DocHelper.LAZY_FIELD_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("field is not lazy and it should be", field.isLazy());
- String value = field.stringValue();
- assertTrue("value is null and it shouldn't be", value != null);
- assertTrue(value + " is not equal to " + DocHelper.LAZY_FIELD_TEXT, value.equals(DocHelper.LAZY_FIELD_TEXT) == true);
- assertTrue("calling stringValue() twice should give different references", field.stringValue() != field.stringValue());
-
- field = doc.getFieldable(DocHelper.TEXT_FIELD_1_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("Field is lazy and it should not be", field.isLazy() == false);
- assertTrue("calling stringValue() twice should give same reference", field.stringValue() == field.stringValue());
-
- field = doc.getFieldable(DocHelper.TEXT_FIELD_UTF1_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("Field is lazy and it should not be", field.isLazy() == false);
- assertTrue(field.stringValue() + " is not equal to " + DocHelper.FIELD_UTF1_TEXT, field.stringValue().equals(DocHelper.FIELD_UTF1_TEXT) == true);
- assertTrue("calling stringValue() twice should give same reference", field.stringValue() == field.stringValue());
-
- field = doc.getFieldable(DocHelper.TEXT_FIELD_UTF2_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("Field is lazy and it should not be", field.isLazy() == true);
- assertTrue(field.stringValue() + " is not equal to " + DocHelper.FIELD_UTF2_TEXT, field.stringValue().equals(DocHelper.FIELD_UTF2_TEXT) == true);
- assertTrue("calling stringValue() twice should give different references", field.stringValue() != field.stringValue());
-
- field = doc.getFieldable(DocHelper.LAZY_FIELD_BINARY_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("stringValue isn't null for lazy binary field", field.stringValue() == null);
- assertTrue("calling binaryValue() twice should give different references", field.getBinaryValue() != field.getBinaryValue());
-
- byte [] bytes = field.getBinaryValue();
- assertTrue("bytes is null and it shouldn't be", bytes != null);
- assertTrue("", DocHelper.LAZY_FIELD_BINARY_BYTES.length == bytes.length);
- for (int i = 0; i < bytes.length; i++) {
- assertTrue("byte[" + i + "] is mismatched", bytes[i] == DocHelper.LAZY_FIELD_BINARY_BYTES[i]);
-
- }
- reader.close();
- }
-
-
-
-
- public void testLazyFieldsAfterClose() throws Exception {
- assertTrue(dir != null);
- assertTrue(fieldInfos != null);
- FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
- assertTrue(reader.size() == 1);
- Set<String> loadFieldNames = new HashSet<String>();
- loadFieldNames.add(DocHelper.TEXT_FIELD_1_KEY);
- loadFieldNames.add(DocHelper.TEXT_FIELD_UTF1_KEY);
- Set<String> lazyFieldNames = new HashSet<String>();
- lazyFieldNames.add(DocHelper.LARGE_LAZY_FIELD_KEY);
- lazyFieldNames.add(DocHelper.LAZY_FIELD_KEY);
- lazyFieldNames.add(DocHelper.LAZY_FIELD_BINARY_KEY);
- lazyFieldNames.add(DocHelper.TEXT_FIELD_UTF2_KEY);
- SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(loadFieldNames, lazyFieldNames);
- Document doc = reader.doc(0, fieldSelector);
- assertTrue("doc is null and it shouldn't be", doc != null);
- Fieldable field = doc.getFieldable(DocHelper.LAZY_FIELD_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("field is not lazy and it should be", field.isLazy());
+ assertTrue(field.storeTermVectors() == false);
+ assertTrue(field.storeTermVectorOffsets() == false);
+ assertTrue(field.storeTermVectorPositions() == false);
+ assertTrue(field.omitNorms() == false);
+ assertTrue(field.indexOptions() == IndexOptions.DOCS_ONLY);
+
+ DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(DocHelper.TEXT_FIELD_3_KEY);
+ reader.document(0, visitor);
+ final List<IndexableField> fields = visitor.getDocument().getFields();
+ assertEquals(1, fields.size());
+ assertEquals(DocHelper.TEXT_FIELD_3_KEY, fields.get(0).name());
reader.close();
- try {
- field.stringValue();
- fail("did not hit AlreadyClosedException as expected");
- } catch (AlreadyClosedException e) {
- // expected
- }
}
- public void testLoadFirst() throws Exception {
- assertTrue(dir != null);
- assertTrue(fieldInfos != null);
- FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
- assertTrue(reader.size() == 1);
- LoadFirstFieldSelector fieldSelector = new LoadFirstFieldSelector();
- Document doc = reader.doc(0, fieldSelector);
- assertTrue("doc is null and it shouldn't be", doc != null);
- int count = 0;
- List<Fieldable> l = doc.getFields();
- for (final Fieldable fieldable : l ) {
- Field field = (Field) fieldable;
-
- assertTrue("field is null and it shouldn't be", field != null);
- String sv = field.stringValue();
- assertTrue("sv is null and it shouldn't be", sv != null);
- count++;
- }
- assertTrue(count + " does not equal: " + 1, count == 1);
- reader.close();
- }
-
- /**
- * Not really a test per se, but we should have some way of assessing whether this is worthwhile.
- * <p/>
- * Must test using a File based directory
- *
- * @throws Exception
- */
- public void testLazyPerformance() throws Exception {
- String userName = System.getProperty("user.name");
- File file = _TestUtil.getTempDir("lazyDir" + userName);
- Directory tmpDir = newFSDirectory(file);
- assertTrue(tmpDir != null);
-
- IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.CREATE).setMergePolicy(newLogMergePolicy());
- ((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(false);
- IndexWriter writer = new IndexWriter(tmpDir, conf);
- writer.addDocument(testDoc);
- writer.close();
-
- assertTrue(fieldInfos != null);
- FieldsReader reader;
- long lazyTime = 0;
- long regularTime = 0;
- int length = 10;
- Set<String> lazyFieldNames = new HashSet<String>();
- lazyFieldNames.add(DocHelper.LARGE_LAZY_FIELD_KEY);
- SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(Collections. <String> emptySet(), lazyFieldNames);
-
- for (int i = 0; i < length; i++) {
- reader = new FieldsReader(tmpDir, TEST_SEGMENT_NAME, fieldInfos);
- assertTrue(reader.size() == 1);
-
- Document doc;
- doc = reader.doc(0, null);//Load all of them
- assertTrue("doc is null and it shouldn't be", doc != null);
- Fieldable field = doc.getFieldable(DocHelper.LARGE_LAZY_FIELD_KEY);
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue("field is lazy", field.isLazy() == false);
- String value;
- long start;
- long finish;
- start = System.currentTimeMillis();
- //On my machine this was always 0ms.
- value = field.stringValue();
- finish = System.currentTimeMillis();
- assertTrue("value is null and it shouldn't be", value != null);
- regularTime += (finish - start);
- reader.close();
- reader = null;
- doc = null;
- //Hmmm, are we still in cache???
- System.gc();
- reader = new FieldsReader(tmpDir, TEST_SEGMENT_NAME, fieldInfos);
- doc = reader.doc(0, fieldSelector);
- field = doc.getFieldable(DocHelper.LARGE_LAZY_FIELD_KEY);
- assertTrue("field is not lazy", field.isLazy() == true);
- start = System.currentTimeMillis();
- //On my machine this took around 50 - 70ms
- value = field.stringValue();
- finish = System.currentTimeMillis();
- assertTrue("value is null and it shouldn't be", value != null);
- lazyTime += (finish - start);
- reader.close();
-
- }
- tmpDir.close();
- if (VERBOSE) {
- System.out.println("Average Non-lazy time (should be very close to zero): " + regularTime / length + " ms for " + length + " reads");
- System.out.println("Average Lazy Time (should be greater than zero): " + lazyTime / length + " ms for " + length + " reads");
- }
- }
-
- public void testLoadSize() throws IOException {
- FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
- Document doc;
-
- doc = reader.doc(0, new FieldSelector(){
- public FieldSelectorResult accept(String fieldName) {
- if (fieldName.equals(DocHelper.TEXT_FIELD_1_KEY) ||
- fieldName.equals(DocHelper.LAZY_FIELD_BINARY_KEY))
- return FieldSelectorResult.SIZE;
- else if (fieldName.equals(DocHelper.TEXT_FIELD_3_KEY))
- return FieldSelectorResult.LOAD;
- else
- return FieldSelectorResult.NO_LOAD;
- }
- });
- Fieldable f1 = doc.getFieldable(DocHelper.TEXT_FIELD_1_KEY);
- Fieldable f3 = doc.getFieldable(DocHelper.TEXT_FIELD_3_KEY);
- Fieldable fb = doc.getFieldable(DocHelper.LAZY_FIELD_BINARY_KEY);
- assertTrue(f1.isBinary());
- assertTrue(!f3.isBinary());
- assertTrue(fb.isBinary());
- assertSizeEquals(2*DocHelper.FIELD_1_TEXT.length(), f1.getBinaryValue());
- assertEquals(DocHelper.FIELD_3_TEXT, f3.stringValue());
- assertSizeEquals(DocHelper.LAZY_FIELD_BINARY_BYTES.length, fb.getBinaryValue());
-
- reader.close();
- }
-
- private void assertSizeEquals(int size, byte[] sizebytes) {
- assertEquals((byte) (size>>>24), sizebytes[0]);
- assertEquals((byte) (size>>>16), sizebytes[1]);
- assertEquals((byte) (size>>> 8), sizebytes[2]);
- assertEquals((byte) size , sizebytes[3]);
- }
public static class FaultyFSDirectory extends Directory {
@@ -528,7 +239,7 @@ public class TestFieldsReader extends Lu
final NumericField.DataType[] typeAnswers = new NumericField.DataType[numDocs];
for(int id=0;id<numDocs;id++) {
Document doc = new Document();
- NumericField nf = new NumericField("nf", Field.Store.YES, false);
+ NumericField nf = new NumericField("nf", NumericField.TYPE_STORED);
doc.add(nf);
final Number answer;
final NumericField.DataType typeAnswer;
@@ -561,7 +272,7 @@ public class TestFieldsReader extends Lu
}
answers[id] = answer;
typeAnswers[id] = typeAnswer;
- doc.add(new NumericField("id", Integer.MAX_VALUE, Field.Store.NO, true).setIntValue(id));
+ doc.add(new NumericField("id", Integer.MAX_VALUE).setIntValue(id));
w.addDocument(doc);
}
final IndexReader r = w.getReader();
@@ -573,11 +284,11 @@ public class TestFieldsReader extends Lu
final int[] ids = FieldCache.DEFAULT.getInts(sub, "id");
for(int docID=0;docID<sub.numDocs();docID++) {
final Document doc = sub.document(docID);
- final Fieldable f = doc.getFieldable("nf");
+ final Field f = (Field) doc.getField("nf");
assertTrue("got f=" + f, f instanceof NumericField);
final NumericField nf = (NumericField) f;
- assertEquals(answers[ids[docID]], nf.getNumericValue());
- assertSame(typeAnswers[ids[docID]], nf.getDataType());
+ assertEquals(answers[ids[docID]], nf.numericValue());
+ assertSame(typeAnswers[ids[docID]], nf.numericDataType());
}
}
r.close();
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java?rev=1162347&r1=1162346&r2=1162347&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java Sat Aug 27 13:27:01 2011
@@ -23,7 +23,7 @@ import org.apache.lucene.util.LuceneTest
import org.apache.lucene.store.Directory;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
+import org.apache.lucene.document.TextField;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.Bits;
@@ -129,15 +129,15 @@ public class TestFilterIndexReader exten
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
Document d1 = new Document();
- d1.add(newField("default","one two", Field.Store.YES, Field.Index.ANALYZED));
+ d1.add(newField("default","one two", TextField.TYPE_STORED));
writer.addDocument(d1);
Document d2 = new Document();
- d2.add(newField("default","one three", Field.Store.YES, Field.Index.ANALYZED));
+ d2.add(newField("default","one three", TextField.TYPE_STORED));
writer.addDocument(d2);
Document d3 = new Document();
- d3.add(newField("default","two four", Field.Store.YES, Field.Index.ANALYZED));
+ d3.add(newField("default","two four", TextField.TYPE_STORED));
writer.addDocument(d3);
writer.close();
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFlex.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFlex.java?rev=1162347&r1=1162346&r2=1162347&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFlex.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFlex.java Sat Aug 27 13:27:01 2011
@@ -39,10 +39,10 @@ public class TestFlex extends LuceneTest
for(int iter=0;iter<2;iter++) {
if (iter == 0) {
Document doc = new Document();
- doc.add(newField("field1", "this is field1", Field.Store.NO, Field.Index.ANALYZED));
- doc.add(newField("field2", "this is field2", Field.Store.NO, Field.Index.ANALYZED));
- doc.add(newField("field3", "aaa", Field.Store.NO, Field.Index.ANALYZED));
- doc.add(newField("field4", "bbb", Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(newField("field1", "this is field1", TextField.TYPE_UNSTORED));
+ doc.add(newField("field2", "this is field2", TextField.TYPE_UNSTORED));
+ doc.add(newField("field3", "aaa", TextField.TYPE_UNSTORED));
+ doc.add(newField("field4", "bbb", TextField.TYPE_UNSTORED));
for(int i=0;i<DOC_COUNT;i++) {
w.addDocument(doc);
}
@@ -66,7 +66,7 @@ public class TestFlex extends LuceneTest
IndexWriter w = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random)).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
Document doc = new Document();
- doc.add(newField("f", "a b c", Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(newField("f", "a b c", TextField.TYPE_UNSTORED));
w.addDocument(doc);
IndexReader r = w.getReader();
TermsEnum terms = r.getSequentialSubReaders()[0].fields().terms("f").iterator();
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestGlobalFieldNumbers.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestGlobalFieldNumbers.java?rev=1162347&r1=1162346&r2=1162347&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestGlobalFieldNumbers.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestGlobalFieldNumbers.java Sat Aug 27 13:27:01 2011
@@ -27,11 +27,11 @@ import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.document.BinaryField;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
-import org.apache.lucene.document.Field.Index;
-import org.apache.lucene.document.Field.Store;
-import org.apache.lucene.document.Field.TermVector;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.TextField;
import org.apache.lucene.index.FieldInfos.FieldNumberBiMap;
import org.apache.lucene.index.codecs.DefaultSegmentInfosWriter;
import org.apache.lucene.store.Directory;
@@ -50,10 +50,8 @@ public class TestGlobalFieldNumbers exte
new MockAnalyzer(random));
IndexWriter writer = new IndexWriter(dir, config);
Document d = new Document();
- d.add(new Field("f1", "d1 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f2", "d1 second field", Store.YES, Index.ANALYZED,
- TermVector.NO));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d1 first field"));
+ d.add(new Field("f2", TextField.TYPE_STORED, "d1 second field"));
writer.addDocument(d);
for (String string : writer.getIndexFileNames()) {
assertFalse(string.endsWith(".fnx"));
@@ -67,9 +65,8 @@ public class TestGlobalFieldNumbers exte
assertFNXFiles(dir, "1.fnx");
d = new Document();
- d.add(new Field("f1", "d2 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f3", new byte[] { 1, 2, 3 }));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d2 first field"));
+ d.add(new BinaryField("f3", new byte[] { 1, 2, 3 }));
writer.addDocument(d);
writer.commit();
files = writer.getIndexFileNames();
@@ -86,11 +83,9 @@ public class TestGlobalFieldNumbers exte
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random)));
Document d = new Document();
- d.add(new Field("f1", "d3 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f2", "d3 second field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f3", new byte[] { 1, 2, 3, 4, 5 }));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d3 first field"));
+ d.add(new Field("f2", TextField.TYPE_STORED, "d3 second field"));
+ d.add(new BinaryField("f3", new byte[] { 1, 2, 3, 4, 5 }));
writer.addDocument(d);
writer.close();
Collection<String> files = writer.getIndexFileNames();
@@ -122,17 +117,14 @@ public class TestGlobalFieldNumbers exte
new MockAnalyzer(random));
IndexWriter writer = new IndexWriter(dir, config);
Document d = new Document();
- d.add(new Field("f1", "d1 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f2", "d1 second field", Store.YES, Index.ANALYZED,
- TermVector.NO));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d1 first field"));
+ d.add(new Field("f2", TextField.TYPE_STORED, "d1 second field"));
writer.addDocument(d);
writer.commit();
assertFNXFiles(dir, "1.fnx");
d = new Document();
- d.add(new Field("f1", "d2 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f3", new byte[] { 1, 2, 3 }));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d2 first field"));
+ d.add(new BinaryField("f3", new byte[] { 1, 2, 3 }));
writer.addDocument(d);
writer.commit();
assertFNXFiles(dir, "2.fnx");
@@ -166,17 +158,14 @@ public class TestGlobalFieldNumbers exte
TEST_VERSION_CURRENT, new MockAnalyzer(random)).setIndexDeletionPolicy(
new KeepAllDeletionPolicy()));
Document d = new Document();
- d.add(new Field("f1", "d1 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f2", "d1 second field", Store.YES, Index.ANALYZED,
- TermVector.NO));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d1 first field"));
+ d.add(new Field("f2", TextField.TYPE_STORED, "d1 second field"));
writer.addDocument(d);
writer.commit();
assertFNXFiles(dir, "1.fnx");
d = new Document();
- d.add(new Field("f1", "d2 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f3", new byte[] { 1, 2, 3 }));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d2 first field"));
+ d.add(new BinaryField("f3", new byte[] { 1, 2, 3 }));
writer.addDocument(d);
writer.commit();
writer.commit();
@@ -190,11 +179,9 @@ public class TestGlobalFieldNumbers exte
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random)));
Document d = new Document();
- d.add(new Field("f1", "d3 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f2", "d3 second field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f3", new byte[] { 1, 2, 3, 4, 5 }));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d3 first field"));
+ d.add(new Field("f2", TextField.TYPE_STORED, "d3 second field"));
+ d.add(new BinaryField("f3", new byte[] { 1, 2, 3, 4, 5 }));
writer.addDocument(d);
writer.close();
assertFNXFiles(dir, "2.fnx");
@@ -217,17 +204,14 @@ public class TestGlobalFieldNumbers exte
TEST_VERSION_CURRENT, new MockAnalyzer(random)).setIndexDeletionPolicy(
new KeepAllDeletionPolicy()));
Document d = new Document();
- d.add(new Field("f1", "d1 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f2", "d1 second field", Store.YES, Index.ANALYZED,
- TermVector.NO));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d1 first field"));
+ d.add(new Field("f2", TextField.TYPE_STORED, "d1 second field"));
writer.addDocument(d);
writer.commit();
assertFNXFiles(dir, "1.fnx");
d = new Document();
- d.add(new Field("f1", "d2 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f3", new byte[] { 1, 2, 3 }));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d2 first field"));
+ d.add(new BinaryField("f3", new byte[] { 1, 2, 3 }));
writer.addDocument(d);
assertFNXFiles(dir, "1.fnx");
writer.close();
@@ -240,9 +224,8 @@ public class TestGlobalFieldNumbers exte
new KeepAllDeletionPolicy()).setIndexCommit(listCommits.get(0)));
d = new Document();
- d.add(new Field("f1", "d2 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
- d.add(new Field("f3", new byte[] { 1, 2, 3 }));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d2 first field"));
+ d.add(new BinaryField("f3", new byte[] { 1, 2, 3 }));
writer.addDocument(d);
writer.commit();
// now we have 3 files since f3 is not present in the first commit
@@ -271,9 +254,13 @@ public class TestGlobalFieldNumbers exte
Document doc = new Document();
final int numFields = 1 + random.nextInt(fieldNames.length);
for (int j = 0; j < numFields; j++) {
+ FieldType customType = new FieldType();
+ customType.setIndexed(true);
+ customType.setTokenized(random.nextBoolean());
+ customType.setOmitNorms(random.nextBoolean());
doc.add(newField(fieldNames[random.nextInt(fieldNames.length)],
_TestUtil.randomRealisticUnicodeString(random),
- Index.toIndex(true, random.nextBoolean(), random.nextBoolean())));
+ customType));
}
writer.addDocument(doc);
@@ -322,9 +309,13 @@ public class TestGlobalFieldNumbers exte
TEST_VERSION_CURRENT, new MockAnalyzer(random)));
Document doc = new Document();
for (String string : fieldNames) {
+ FieldType customType = new FieldType();
+ customType.setIndexed(true);
+ customType.setTokenized(random.nextBoolean());
+ customType.setOmitNorms(random.nextBoolean());
doc.add(newField(string,
_TestUtil.randomRealisticUnicodeString(random),
- Index.toIndex(true, random.nextBoolean(), random.nextBoolean())));
+ customType));
}
writer.addDocument(doc);
@@ -419,8 +410,12 @@ public class TestGlobalFieldNumbers exte
String name = copySortedMap.get(nextField);
assertNotNull(name);
+ FieldType customType = new FieldType();
+ customType.setIndexed(true);
+ customType.setTokenized(random.nextBoolean());
+ customType.setOmitNorms(random.nextBoolean());
doc.add(newField(name, _TestUtil.randomRealisticUnicodeString(random),
- Index.toIndex(true, random.nextBoolean(), random.nextBoolean())));
+ customType));
writer.addDocument(doc);
if (random.nextInt(10) == 0) {
writer.commit();
@@ -480,8 +475,7 @@ public class TestGlobalFieldNumbers exte
}
Document d = new Document();
- d.add(new Field("f1", "d1 first field", Store.YES, Index.ANALYZED,
- TermVector.NO));
+ d.add(new Field("f1", TextField.TYPE_STORED, "d1 first field"));
writer.addDocument(d);
writer.prepareCommit();
// the fnx file should still be under control of the SIS
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java?rev=1162347&r1=1162346&r2=1162347&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java Sat Aug 27 13:27:01 2011
@@ -17,20 +17,21 @@ package org.apache.lucene.index;
* limitations under the License.
*/
-import org.apache.lucene.util.LuceneTestCase;
+import java.io.*;
+import java.util.*;
+
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.search.DefaultSimilarity;
import org.apache.lucene.store.CompoundFileDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.MockDirectoryWrapper;
-import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexWriterConfig.OpenMode;
-
-import java.io.*;
-import java.util.*;
+import org.apache.lucene.util.LuceneTestCase;
/*
Verify we can read the pre-2.1 file format, do searches
@@ -229,8 +230,8 @@ public class TestIndexFileDeleter extend
private void addDoc(IndexWriter writer, int id) throws IOException
{
Document doc = new Document();
- doc.add(newField("content", "aaa", Field.Store.NO, Field.Index.ANALYZED));
- doc.add(newField("id", Integer.toString(id), Field.Store.YES, Field.Index.NOT_ANALYZED));
+ doc.add(newField("content", "aaa", TextField.TYPE_UNSTORED));
+ doc.add(newField("id", Integer.toString(id), StringField.TYPE_UNSTORED));
writer.addDocument(doc);
}
}
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java?rev=1162347&r1=1162346&r2=1162347&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java Sat Aug 27 13:27:01 2011
@@ -31,27 +31,22 @@ import java.util.Set;
import java.util.SortedSet;
import org.junit.Assume;
import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.document.BinaryField;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
-import org.apache.lucene.document.FieldSelector;
-import org.apache.lucene.document.Fieldable;
-import org.apache.lucene.document.SetBasedFieldSelector;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexReader.FieldOption;
import org.apache.lucene.index.codecs.CodecProvider;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.search.DefaultSimilarity;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.FieldCache;
-import org.apache.lucene.search.Similarity;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.ScoreDoc;
-import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockObtainFailedException;
-import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.NoSuchDirectoryException;
-import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.store.LockReleaseFailedException;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
@@ -154,10 +149,14 @@ public class TestIndexReader extends Luc
);
Document doc = new Document();
- doc.add(new Field("keyword","test1", Field.Store.YES, Field.Index.NOT_ANALYZED));
- doc.add(new Field("text","test1", Field.Store.YES, Field.Index.ANALYZED));
- doc.add(new Field("unindexed","test1", Field.Store.YES, Field.Index.NO));
- doc.add(new Field("unstored","test1", Field.Store.NO, Field.Index.ANALYZED));
+
+ FieldType customType3 = new FieldType();
+ customType3.setStored(true);
+
+ doc.add(new Field("keyword",StringField.TYPE_STORED,"test1"));
+ doc.add(new Field("text",TextField.TYPE_STORED,"test1"));
+ doc.add(new Field("unindexed",customType3,"test1"));
+ doc.add(new TextField("unstored","test1"));
writer.addDocument(doc);
writer.close();
@@ -180,29 +179,43 @@ public class TestIndexReader extends Luc
int mergeFactor = ((LogMergePolicy) writer.getConfig().getMergePolicy()).getMergeFactor();
for (int i = 0; i < 5*mergeFactor; i++) {
doc = new Document();
- doc.add(new Field("keyword","test1", Field.Store.YES, Field.Index.NOT_ANALYZED));
- doc.add(new Field("text","test1", Field.Store.YES, Field.Index.ANALYZED));
- doc.add(new Field("unindexed","test1", Field.Store.YES, Field.Index.NO));
- doc.add(new Field("unstored","test1", Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(new Field("keyword",StringField.TYPE_STORED,"test1"));
+ doc.add(new Field("text",TextField.TYPE_STORED, "test1"));
+ doc.add(new Field("unindexed",customType3,"test1"));
+ doc.add(new TextField("unstored","test1"));
writer.addDocument(doc);
}
// new fields are in some different segments (we hope)
for (int i = 0; i < 5*mergeFactor; i++) {
doc = new Document();
- doc.add(new Field("keyword2","test1", Field.Store.YES, Field.Index.NOT_ANALYZED));
- doc.add(new Field("text2","test1", Field.Store.YES, Field.Index.ANALYZED));
- doc.add(new Field("unindexed2","test1", Field.Store.YES, Field.Index.NO));
- doc.add(new Field("unstored2","test1", Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(new Field("keyword2",StringField.TYPE_STORED,"test1"));
+ doc.add(new Field("text2",TextField.TYPE_STORED, "test1"));
+ doc.add(new Field("unindexed2",customType3,"test1"));
+ doc.add(new TextField("unstored2","test1"));
writer.addDocument(doc);
}
// new termvector fields
+
+ FieldType customType5 = new FieldType(TextField.TYPE_STORED);
+ customType5.setStoreTermVectors(true);
+ FieldType customType6 = new FieldType(TextField.TYPE_STORED);
+ customType6.setStoreTermVectors(true);
+ customType6.setStoreTermVectorOffsets(true);
+ FieldType customType7 = new FieldType(TextField.TYPE_STORED);
+ customType7.setStoreTermVectors(true);
+ customType7.setStoreTermVectorPositions(true);
+ FieldType customType8 = new FieldType(TextField.TYPE_STORED);
+ customType8.setStoreTermVectors(true);
+ customType8.setStoreTermVectorOffsets(true);
+ customType8.setStoreTermVectorPositions(true);
+
for (int i = 0; i < 5*mergeFactor; i++) {
doc = new Document();
- doc.add(new Field("tvnot","tvnot", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
- doc.add(new Field("termvector","termvector", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
- doc.add(new Field("tvoffset","tvoffset", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_OFFSETS));
- doc.add(new Field("tvposition","tvposition", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS));
- doc.add(newField("tvpositionoffset","tvpositionoffset", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
+ doc.add(new Field("tvnot",TextField.TYPE_STORED,"tvnot"));
+ doc.add(new Field("termvector",customType5,"termvector"));
+ doc.add(new Field("tvoffset",customType6,"tvoffset"));
+ doc.add(new Field("tvposition",customType7,"tvposition"));
+ doc.add(new Field("tvpositionoffset",customType8, "tvpositionoffset"));
writer.addDocument(doc);
}
@@ -277,14 +290,26 @@ public class TestIndexReader extends Luc
// want to get some more segments here
// new termvector fields
int mergeFactor = ((LogMergePolicy) writer.getConfig().getMergePolicy()).getMergeFactor();
+ FieldType customType5 = new FieldType(TextField.TYPE_STORED);
+ customType5.setStoreTermVectors(true);
+ FieldType customType6 = new FieldType(TextField.TYPE_STORED);
+ customType6.setStoreTermVectors(true);
+ customType6.setStoreTermVectorOffsets(true);
+ FieldType customType7 = new FieldType(TextField.TYPE_STORED);
+ customType7.setStoreTermVectors(true);
+ customType7.setStoreTermVectorPositions(true);
+ FieldType customType8 = new FieldType(TextField.TYPE_STORED);
+ customType8.setStoreTermVectors(true);
+ customType8.setStoreTermVectorOffsets(true);
+ customType8.setStoreTermVectorPositions(true);
for (int i = 0; i < 5 * mergeFactor; i++) {
Document doc = new Document();
- doc.add(new Field("tvnot","one two two three three three", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
- doc.add(new Field("termvector","one two two three three three", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
- doc.add(new Field("tvoffset","one two two three three three", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_OFFSETS));
- doc.add(new Field("tvposition","one two two three three three", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS));
- doc.add(new Field("tvpositionoffset","one two two three three three", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
-
+ doc.add(new Field("tvnot",TextField.TYPE_STORED,"one two two three three three"));
+ doc.add(new Field("termvector",customType5,"one two two three three three"));
+ doc.add(new Field("tvoffset",customType6,"one two two three three three"));
+ doc.add(new Field("tvposition",customType7,"one two two three three three"));
+ doc.add(new Field("tvpositionoffset",customType8, "one two two three three three"));
+
writer.addDocument(doc);
}
writer.close();
@@ -338,36 +363,21 @@ public class TestIndexReader extends Luc
writer.close();
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.APPEND).setMergePolicy(newLogMergePolicy()));
Document doc = new Document();
- doc.add(new Field("bin1", bin));
- doc.add(new Field("junk", "junk text", Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(new BinaryField("bin1", bin));
+ doc.add(new TextField("junk", "junk text"));
writer.addDocument(doc);
writer.close();
IndexReader reader = IndexReader.open(dir, false);
- doc = reader.document(reader.maxDoc() - 1);
- Field[] fields = doc.getFields("bin1");
+ Document doc2 = reader.document(reader.maxDoc() - 1);
+ IndexableField[] fields = doc2.getFields("bin1");
assertNotNull(fields);
assertEquals(1, fields.length);
- Field b1 = fields[0];
- assertTrue(b1.isBinary());
- byte[] data1 = b1.getBinaryValue();
- assertEquals(bin.length, b1.getBinaryLength());
- for (int i = 0; i < bin.length; i++) {
- assertEquals(bin[i], data1[i + b1.getBinaryOffset()]);
- }
- Set<String> lazyFields = new HashSet<String>();
- lazyFields.add("bin1");
- FieldSelector sel = new SetBasedFieldSelector(new HashSet<String>(), lazyFields);
- doc = reader.document(reader.maxDoc() - 1, sel);
- Fieldable[] fieldables = doc.getFieldables("bin1");
- assertNotNull(fieldables);
- assertEquals(1, fieldables.length);
- Fieldable fb1 = fieldables[0];
- assertTrue(fb1.isBinary());
- assertEquals(bin.length, fb1.getBinaryLength());
- data1 = fb1.getBinaryValue();
- assertEquals(bin.length, fb1.getBinaryLength());
+ IndexableField b1 = fields[0];
+ assertTrue(b1.binaryValue() != null);
+ BytesRef bytesRef = b1.binaryValue();
+ assertEquals(bin.length, bytesRef.length);
for (int i = 0; i < bin.length; i++) {
- assertEquals(bin[i], data1[i + fb1.getBinaryOffset()]);
+ assertEquals(bin[i], bytesRef.bytes[i + bytesRef.offset]);
}
reader.close();
// force optimize
@@ -377,16 +387,16 @@ public class TestIndexReader extends Luc
writer.optimize();
writer.close();
reader = IndexReader.open(dir, false);
- doc = reader.document(reader.maxDoc() - 1);
- fields = doc.getFields("bin1");
+ doc2 = reader.document(reader.maxDoc() - 1);
+ fields = doc2.getFields("bin1");
assertNotNull(fields);
assertEquals(1, fields.length);
b1 = fields[0];
- assertTrue(b1.isBinary());
- data1 = b1.getBinaryValue();
- assertEquals(bin.length, b1.getBinaryLength());
+ assertTrue(b1.binaryValue() != null);
+ bytesRef = b1.binaryValue();
+ assertEquals(bin.length, bytesRef.length);
for (int i = 0; i < bin.length; i++) {
- assertEquals(bin[i], data1[i + b1.getBinaryOffset()]);
+ assertEquals(bin[i], bytesRef.bytes[i + bytesRef.offset]);
}
reader.close();
dir.close();
@@ -778,38 +788,56 @@ public class TestIndexReader extends Luc
static void addDocumentWithFields(IndexWriter writer) throws IOException
{
Document doc = new Document();
- doc.add(newField("keyword","test1", Field.Store.YES, Field.Index.NOT_ANALYZED));
- doc.add(newField("text","test1", Field.Store.YES, Field.Index.ANALYZED));
- doc.add(newField("unindexed","test1", Field.Store.YES, Field.Index.NO));
- doc.add(newField("unstored","test1", Field.Store.NO, Field.Index.ANALYZED));
+
+ FieldType customType3 = new FieldType();
+ customType3.setStored(true);
+ doc.add(newField("keyword", "test1", StringField.TYPE_STORED));
+ doc.add(newField("text", "test1", TextField.TYPE_STORED));
+ doc.add(newField("unindexed", "test1", customType3));
+ doc.add(new TextField("unstored","test1"));
writer.addDocument(doc);
}
static void addDocumentWithDifferentFields(IndexWriter writer) throws IOException
{
- Document doc = new Document();
- doc.add(newField("keyword2","test1", Field.Store.YES, Field.Index.NOT_ANALYZED));
- doc.add(newField("text2","test1", Field.Store.YES, Field.Index.ANALYZED));
- doc.add(newField("unindexed2","test1", Field.Store.YES, Field.Index.NO));
- doc.add(newField("unstored2","test1", Field.Store.NO, Field.Index.ANALYZED));
- writer.addDocument(doc);
+ Document doc = new Document();
+
+ FieldType customType3 = new FieldType();
+ customType3.setStored(true);
+ doc.add(newField("keyword2", "test1", StringField.TYPE_STORED));
+ doc.add(newField("text2", "test1", TextField.TYPE_STORED));
+ doc.add(newField("unindexed2", "test1", customType3));
+ doc.add(new TextField("unstored2","test1"));
+ writer.addDocument(doc);
}
static void addDocumentWithTermVectorFields(IndexWriter writer) throws IOException
{
Document doc = new Document();
- doc.add(newField("tvnot","tvnot", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
- doc.add(newField("termvector","termvector", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
- doc.add(newField("tvoffset","tvoffset", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_OFFSETS));
- doc.add(newField("tvposition","tvposition", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS));
- doc.add(newField("tvpositionoffset","tvpositionoffset", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
+ FieldType customType5 = new FieldType(TextField.TYPE_STORED);
+ customType5.setStoreTermVectors(true);
+ FieldType customType6 = new FieldType(TextField.TYPE_STORED);
+ customType6.setStoreTermVectors(true);
+ customType6.setStoreTermVectorOffsets(true);
+ FieldType customType7 = new FieldType(TextField.TYPE_STORED);
+ customType7.setStoreTermVectors(true);
+ customType7.setStoreTermVectorPositions(true);
+ FieldType customType8 = new FieldType(TextField.TYPE_STORED);
+ customType8.setStoreTermVectors(true);
+ customType8.setStoreTermVectorOffsets(true);
+ customType8.setStoreTermVectorPositions(true);
+ doc.add(newField("tvnot","tvnot",TextField.TYPE_STORED));
+ doc.add(newField("termvector","termvector",customType5));
+ doc.add(newField("tvoffset","tvoffset", customType6));
+ doc.add(newField("tvposition","tvposition", customType7));
+ doc.add(newField("tvpositionoffset","tvpositionoffset", customType8));
writer.addDocument(doc);
}
static void addDoc(IndexWriter writer, String value) throws IOException {
Document doc = new Document();
- doc.add(newField("content", value, Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(newField("content", value, TextField.TYPE_UNSTORED));
writer.addDocument(doc);
}
@@ -862,11 +890,11 @@ public class TestIndexReader extends Luc
if (liveDocs1 == null || liveDocs1.get(i)) {
Document doc1 = index1.document(i);
Document doc2 = index2.document(i);
- List<Fieldable> fieldable1 = doc1.getFields();
- List<Fieldable> fieldable2 = doc2.getFields();
- assertEquals("Different numbers of fields for doc " + i + ".", fieldable1.size(), fieldable2.size());
- Iterator<Fieldable> itField1 = fieldable1.iterator();
- Iterator<Fieldable> itField2 = fieldable2.iterator();
+ List<IndexableField> field1 = doc1.getFields();
+ List<IndexableField> field2 = doc2.getFields();
+ assertEquals("Different numbers of fields for doc " + i + ".", field1.size(), field2.size());
+ Iterator<IndexableField> itField1 = field1.iterator();
+ Iterator<IndexableField> itField2 = field2.iterator();
while (itField1.hasNext()) {
Field curField1 = (Field) itField1.next();
Field curField2 = (Field) itField2.next();
@@ -1047,7 +1075,11 @@ public class TestIndexReader extends Luc
static Document createDocument(String id) {
Document doc = new Document();
- doc.add(newField("id", id, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
+ FieldType customType = new FieldType(TextField.TYPE_STORED);
+ customType.setTokenized(false);
+ customType.setOmitNorms(true);
+
+ doc.add(newField("id", id, customType));
return doc;
}
@@ -1097,7 +1129,7 @@ public class TestIndexReader extends Luc
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
Document doc = new Document();
- doc.add(newField("number", "17", Field.Store.NO, Field.Index.NOT_ANALYZED));
+ doc.add(newField("number", "17", StringField.TYPE_UNSTORED));
writer.addDocument(doc);
writer.close();
@@ -1132,7 +1164,7 @@ public class TestIndexReader extends Luc
setMergePolicy(newLogMergePolicy(10))
);
Document doc = new Document();
- doc.add(newField("number", "17", Field.Store.NO, Field.Index.NOT_ANALYZED));
+ doc.add(newField("number", "17", StringField.TYPE_UNSTORED));
writer.addDocument(doc);
writer.commit();
@@ -1164,8 +1196,8 @@ public class TestIndexReader extends Luc
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
Document doc = new Document();
- doc.add(newField("field", "a b c d e f g h i j k l m n o p q r s t u v w x y z", Field.Store.NO, Field.Index.ANALYZED));
- doc.add(newField("number", "0 1 2 3 4 5 6 7 8 9", Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(newField("field", "a b c d e f g h i j k l m n o p q r s t u v w x y z", TextField.TYPE_UNSTORED));
+ doc.add(newField("number", "0 1 2 3 4 5 6 7 8 9", TextField.TYPE_UNSTORED));
writer.addDocument(doc);
writer.addDocument(doc);
writer.commit();
@@ -1197,8 +1229,8 @@ public class TestIndexReader extends Luc
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
Document doc = new Document();
- doc.add(newField("field", "a b c d e f g h i j k l m n o p q r s t u v w x y z", Field.Store.NO, Field.Index.ANALYZED));
- doc.add(newField("number", "0 1 2 3 4 5 6 7 8 9", Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(newField("field", "a b c d e f g h i j k l m n o p q r s t u v w x y z", TextField.TYPE_UNSTORED));
+ doc.add(newField("number", "0 1 2 3 4 5 6 7 8 9", TextField.TYPE_UNSTORED));
writer.addDocument(doc);
writer.addDocument(doc);
writer.close();
@@ -1302,7 +1334,7 @@ public class TestIndexReader extends Luc
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
Document d = new Document();
- d.add(newField("f", "a a b", Field.Index.ANALYZED));
+ d.add(newField("f", "a a b", TextField.TYPE_UNSTORED));
writer.addDocument(d);
IndexReader r = writer.getReader();
writer.close();
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java?rev=1162347&r1=1162346&r2=1162347&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java Sat Aug 27 13:27:01 2011
@@ -17,12 +17,10 @@ package org.apache.lucene.index;
* limitations under the License.
*/
-import org.apache.lucene.index.SegmentNorms;
import org.apache.lucene.search.DefaultSimilarity;
-import org.apache.lucene.search.Similarity;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
+import org.apache.lucene.document.TextField;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.LuceneTestCase;
@@ -500,7 +498,7 @@ public class TestIndexReaderClone extend
setMergePolicy(newLogMergePolicy(false))
);
Document doc = new Document();
- doc.add(newField("field", "yes it's stored", Field.Store.YES, Field.Index.ANALYZED));
+ doc.add(newField("field", "yes it's stored", TextField.TYPE_STORED));
w.addDocument(doc);
w.close();
IndexReader r1 = IndexReader.open(dir, false);
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java?rev=1162347&r1=1162346&r2=1162347&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java Sat Aug 27 13:27:01 2011
@@ -26,10 +26,9 @@ import org.apache.lucene.analysis.Analyz
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
-import org.apache.lucene.document.Field.Index;
-import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
-import org.apache.lucene.index.SegmentNorms;
import org.apache.lucene.search.DefaultSimilarity;
import org.apache.lucene.search.DefaultSimilarityProvider;
import org.apache.lucene.search.Similarity;
@@ -329,8 +328,11 @@ public class TestIndexReaderCloneNorms e
private Document newDoc() {
Document d = new Document();
float boost = nextNorm("anyfield"); // in this test the same similarity is used for all fields so it does not matter what field is passed
+
+ FieldType customType = new FieldType(TextField.TYPE_UNSTORED);
+ customType.setTokenized(false);
for (int i = 0; i < 10; i++) {
- Field f = newField("f" + i, "v" + i, Store.NO, Index.NOT_ANALYZED);
+ Field f = newField("f" + i, "v" + i, customType);
f.setBoost(boost);
d.add(f);
}
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderDelete.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderDelete.java?rev=1162347&r1=1162346&r2=1162347&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderDelete.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderDelete.java Sat Aug 27 13:27:01 2011
@@ -21,7 +21,7 @@ import java.io.IOException;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
+import org.apache.lucene.document.StringField;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
@@ -276,11 +276,11 @@ public class TestIndexReaderDelete exten
Directory dir = newDirectory();
RandomIndexWriter w= new RandomIndexWriter(random, dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setMergePolicy(newLogMergePolicy()));
Document doc = new Document();
- doc.add(newField("f", "doctor", Field.Store.NO, Field.Index.NOT_ANALYZED));
+ doc.add(newField("f", "doctor", StringField.TYPE_UNSTORED));
w.addDocument(doc);
doc = new Document();
w.commit();
- doc.add(newField("f", "who", Field.Store.NO, Field.Index.NOT_ANALYZED));
+ doc.add(newField("f", "who", StringField.TYPE_UNSTORED));
w.addDocument(doc);
IndexReader r = new SlowMultiReaderWrapper(w.getReader());
w.close();
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderOnDiskFull.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderOnDiskFull.java?rev=1162347&r1=1162346&r2=1162347&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderOnDiskFull.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderOnDiskFull.java Sat Aug 27 13:27:01 2011
@@ -21,11 +21,11 @@ import java.io.IOException;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.document.TextField;
import org.apache.lucene.search.DefaultSimilarity;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
-import org.apache.lucene.search.Similarity;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.RAMDirectory;
@@ -52,8 +52,8 @@ public class TestIndexReaderOnDiskFull e
}
for(int i=0;i<157;i++) {
Document d = new Document();
- d.add(newField("id", Integer.toString(i), Field.Store.YES, Field.Index.NOT_ANALYZED));
- d.add(newField("content", "aaa " + i, Field.Store.NO, Field.Index.ANALYZED));
+ d.add(newField("id", Integer.toString(i), StringField.TYPE_STORED));
+ d.add(newField("content", "aaa " + i, TextField.TYPE_UNSTORED));
writer.addDocument(d);
if (0==i%10)
writer.commit();
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java?rev=1162347&r1=1162346&r2=1162347&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java Sat Aug 27 13:27:01 2011
@@ -17,7 +17,6 @@ package org.apache.lucene.index;
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -31,16 +30,15 @@ import java.util.Set;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field.Index;
-import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.search.DefaultSimilarity;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
-import org.apache.lucene.search.Similarity;
-import org.apache.lucene.search.SimilarityProvider;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory;
@@ -168,12 +166,19 @@ public class TestIndexReaderReopen exten
IndexReader reader = IndexReader.open(dir, false);
try {
int M = 3;
+ FieldType customType = new FieldType(TextField.TYPE_STORED);
+ customType.setTokenized(false);
+ FieldType customType2 = new FieldType(TextField.TYPE_STORED);
+ customType2.setTokenized(false);
+ customType2.setOmitNorms(true);
+ FieldType customType3 = new FieldType();
+ customType3.setStored(true);
for (int i=0; i<4; i++) {
for (int j=0; j<M; j++) {
Document doc = new Document();
- doc.add(newField("id", i+"_"+j, Store.YES, Index.NOT_ANALYZED));
- doc.add(newField("id2", i+"_"+j, Store.YES, Index.NOT_ANALYZED_NO_NORMS));
- doc.add(newField("id3", i+"_"+j, Store.YES, Index.NO));
+ doc.add(newField("id", i+"_"+j, customType));
+ doc.add(newField("id2", i+"_"+j, customType2));
+ doc.add(newField("id3", i+"_"+j, customType3));
iwriter.addDocument(doc);
if (i>0) {
int k = i-1;
@@ -957,13 +962,18 @@ public class TestIndexReaderReopen exten
Document doc = new Document();
sb.append("a");
sb.append(n);
- doc.add(new Field("field1", sb.toString(), Store.YES, Index.ANALYZED));
- doc.add(new Field("fielda", sb.toString(), Store.YES, Index.NOT_ANALYZED_NO_NORMS));
- doc.add(new Field("fieldb", sb.toString(), Store.YES, Index.NO));
+ FieldType customType2 = new FieldType(TextField.TYPE_STORED);
+ customType2.setTokenized(false);
+ customType2.setOmitNorms(true);
+ FieldType customType3 = new FieldType();
+ customType3.setStored(true);
+ doc.add(new Field("field1", TextField.TYPE_STORED, sb.toString()));
+ doc.add(new Field("fielda", customType2, sb.toString()));
+ doc.add(new Field("fieldb", customType3, sb.toString()));
sb.append(" b");
sb.append(n);
for (int i = 1; i < numFields; i++) {
- doc.add(new Field("field" + (i+1), sb.toString(), Store.YES, Index.ANALYZED));
+ doc.add(new Field("field" + (i+1), TextField.TYPE_STORED, sb.toString()));
}
return doc;
}
@@ -1178,7 +1188,7 @@ public class TestIndexReaderReopen exten
);
for(int i=0;i<4;i++) {
Document doc = new Document();
- doc.add(newField("id", ""+i, Field.Store.NO, Field.Index.NOT_ANALYZED));
+ doc.add(newField("id", ""+i, StringField.TYPE_UNSTORED));
writer.addDocument(doc);
Map<String,String> data = new HashMap<String,String>();
data.put("index", i+"");
@@ -1239,7 +1249,7 @@ public class TestIndexReaderReopen exten
setMergePolicy(newLogMergePolicy(10))
);
Document doc = new Document();
- doc.add(newField("number", "17", Field.Store.NO, Field.Index.NOT_ANALYZED));
+ doc.add(newField("number", "17", StringField.TYPE_UNSTORED));
writer.addDocument(doc);
writer.commit();