lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1441644 - in /lucene/dev/branches/lucene4547/lucene/core/src: java/org/apache/lucene/index/FieldInfos.java test/org/apache/lucene/index/TestDocValuesIndexing.java
Date Fri, 01 Feb 2013 21:38:02 GMT
Author: mikemccand
Date: Fri Feb  1 21:38:01 2013
New Revision: 1441644

URL: http://svn.apache.org/viewvc?rev=1441644&view=rev
Log:
fix nocommits

Modified:
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
    lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java?rev=1441644&r1=1441643&r2=1441644&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
(original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
Fri Feb  1 21:38:01 2013
@@ -163,7 +163,14 @@ public class FieldInfos implements Itera
     
     private final Map<Integer,String> numberToName;
     private final Map<String,Integer> nameToNumber;
+    // We use this to enforce that a given field never
+    // changes DV type, even across segments / IndexWriter
+    // sessions:
     private final Map<String,DocValuesType> docValuesType;
+
+    // TODO: we should similarly catch an attempt to turn
+    // norms back on after they were already ommitted; today
+    // we silently discard the norm but this is badly trappy
     private int lowestUnassignedFieldNumber = -1;
     
     FieldNumbers() {
@@ -209,26 +216,8 @@ public class FieldInfos implements Itera
       return fieldNumber.intValue();
     }
 
-    /**
-     * Sets the given field number and name if not yet set. 
-     */
-    // nocommit: why is docvalues involved with global field numbers?
-    // nocommit: and is it even tested...
-    /*
-    synchronized void setIfNotSet(int fieldNumber, String fieldName, DocValuesType dvType)
{
-      final Integer boxedFieldNumber = Integer.valueOf(fieldNumber);
-      if (!numberToName.containsKey(boxedFieldNumber)
-          && !nameToNumber.containsKey(fieldName)
-          && !docValuesType.containsKey(dvType)) {
-        numberToName.put(boxedFieldNumber, fieldName);
-        nameToNumber.put(fieldName, boxedFieldNumber);
-        docValuesType.put(fieldName, dvType);
-      } else {
-        // nocommit should this be a real check?
-        assert containsConsistent(boxedFieldNumber, fieldName, dvType);
-      }
-    }
-    */
+    // nocommit: do we need better tests for attempt to
+    // change doc value type across segments...
     
     // used by assert
     synchronized boolean containsConsistent(Integer number, String name, DocValuesType dvType)
{

Modified: lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java?rev=1441644&r1=1441643&r2=1441644&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
(original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
Fri Feb  1 21:38:01 2013
@@ -610,11 +610,116 @@ public class TestDocValuesIndexing exten
     writer.close();
     conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
     writer = new IndexWriter(dir, conf);
-    writer.deleteAll();
     doc = new Document();
     doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
     writer.addDocument(doc);
     writer.close();
     dir.close();
   }
+
+  public void testTypeChangeViaAddIndexes() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
+    IndexWriter writer = new IndexWriter(dir, conf);
+    Document doc = new Document();
+    doc.add(new NumericDocValuesField("dv", 0L));
+    writer.addDocument(doc);
+    writer.close();
+
+    Directory dir2 = newDirectory();
+    writer = new IndexWriter(dir2, conf);
+    doc = new Document();
+    doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+    writer.addDocument(doc);
+    try {
+      writer.addIndexes(dir);
+      fail("did not hit exception");
+    } catch (IllegalArgumentException iae) {
+      // expected
+    }
+    writer.close();
+
+    dir.close();
+    dir2.close();
+  }
+
+  public void testTypeChangeViaAddIndexesIR() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
+    IndexWriter writer = new IndexWriter(dir, conf);
+    Document doc = new Document();
+    doc.add(new NumericDocValuesField("dv", 0L));
+    writer.addDocument(doc);
+    writer.close();
+
+    Directory dir2 = newDirectory();
+    writer = new IndexWriter(dir2, conf);
+    doc = new Document();
+    doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+    writer.addDocument(doc);
+    IndexReader[] readers = new IndexReader[] {DirectoryReader.open(dir)};
+    try {
+      writer.addIndexes(readers);
+      fail("did not hit exception");
+    } catch (IllegalArgumentException iae) {
+      // expected
+    }
+    readers[0].close();
+    writer.close();
+
+    dir.close();
+    dir2.close();
+  }
+
+  public void testTypeChangeViaAddIndexes2() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
+    IndexWriter writer = new IndexWriter(dir, conf);
+    Document doc = new Document();
+    doc.add(new NumericDocValuesField("dv", 0L));
+    writer.addDocument(doc);
+    writer.close();
+
+    Directory dir2 = newDirectory();
+    writer = new IndexWriter(dir2, conf);
+    writer.addIndexes(dir);
+    doc = new Document();
+    doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+    try {
+      writer.addDocument(doc);
+      fail("did not hit exception");
+    } catch (IllegalArgumentException iae) {
+      // expected
+    }
+    writer.close();
+    dir2.close();
+    dir.close();
+  }
+
+  public void testTypeChangeViaAddIndexesIR2() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
+    IndexWriter writer = new IndexWriter(dir, conf);
+    Document doc = new Document();
+    doc.add(new NumericDocValuesField("dv", 0L));
+    writer.addDocument(doc);
+    writer.close();
+
+    Directory dir2 = newDirectory();
+    writer = new IndexWriter(dir2, conf);
+    IndexReader[] readers = new IndexReader[] {DirectoryReader.open(dir)};
+    writer.addIndexes(readers);
+    readers[0].close();
+    doc = new Document();
+    doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
+    try {
+      writer.addDocument(doc);
+      fail("did not hit exception");
+    } catch (IllegalArgumentException iae) {
+      // expected
+    }
+    writer.close();
+    dir2.close();
+    dir.close();
+  }
 }



Mime
View raw message