Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

fix wrong comment; add test proving it's wrong; add mixed codec tests

Mike McCandlessddbf3a216872
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60PointWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60PointWriter.java
index 01491fdcdc8..74acb4d30ee 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60PointWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60PointWriter.java
@@ -141,11 +141,17 @@ public class Lucene60PointWriter extends PointWriter implements Closeable {
for(int i=0;i<mergeState.pointReaders.length;i++) {
PointReader reader = mergeState.pointReaders[i];
- Lucene60PointReader reader60 = (Lucene60PointReader) reader;
- if (reader60 != null) {
- // TODO: I could just use the merged fieldInfo.number instead of resolving to this
- // reader's FieldInfo, right? Field numbers are always consistent across segments,
- // since when?
+ if (reader != null) {
+
+ // we confirmed this up above
+ assert reader instanceof Lucene60PointReader;
+ Lucene60PointReader reader60 = (Lucene60PointReader) reader;
+
+ // NOTE: we cannot just use the merged fieldInfo.number (instead of resolving to this
+ // reader's FieldInfo as we do below) because field numbers can easily be different
+ // when addIndexes(Directory...) copies over segments from another index:
+
+
FieldInfos readerFieldInfos = mergeState.fieldInfos[i];
FieldInfo readerFieldInfo = readerFieldInfos.fieldInfo(fieldInfo.name);
if (readerFieldInfo != null) {
diff --git a/lucene/core/src/java/org/apache/lucene/index/PointValues.java b/lucene/core/src/java/org/apache/lucene/index/PointValues.java
index e786bad813d..488baeb26d4 100644
--- a/lucene/core/src/java/org/apache/lucene/index/PointValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/PointValues.java
@@ -1,9 +1,5 @@
package org.apache.lucene.index;
-import java.io.IOException;
-
-import org.apache.lucene.util.bkd.BKDWriter;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -21,6 +17,10 @@ import org.apache.lucene.util.bkd.BKDWriter;
* limitations under the License.
*/
+import java.io.IOException;
+
+import org.apache.lucene.util.bkd.BKDWriter;
+
/** Allows recursively visiting point values indexed with {@link org.apache.lucene.document.IntPoint},
* {@link org.apache.lucene.document.FloatPoint}, {@link org.apache.lucene.document.LongPoint}, {@link org.apache.lucene.document.DoublePoint}
* or {@link org.apache.lucene.document.BinaryPoint}.
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
index 6d0a82ffc50..738109e36ce 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
@@ -18,10 +18,11 @@ package org.apache.lucene.index;
*/
import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.codecs.Codec;
import org.apache.lucene.document.BinaryPoint;
-import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
+import org.apache.lucene.document.IntPoint;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
@@ -388,4 +389,50 @@ public class TestPointValues extends LuceneTestCase {
w.close();
dir.close();
}
+
+ // Write point values, one segment with Lucene60, another with SimpleText, then forceMerge with SimpleText
+ public void testDifferentCodecs1() throws Exception {
+ Directory dir = newDirectory();
+ IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
+ iwc.setCodec(Codec.forName("Lucene60"));
+ IndexWriter w = new IndexWriter(dir, iwc);
+ Document doc = new Document();
+ doc.add(new IntPoint("int", 1));
+ w.addDocument(doc);
+ w.close();
+
+ iwc = new IndexWriterConfig(new MockAnalyzer(random()));
+ iwc.setCodec(Codec.forName("SimpleText"));
+ w = new IndexWriter(dir, iwc);
+ doc = new Document();
+ doc.add(new IntPoint("int", 1));
+ w.addDocument(doc);
+
+ w.forceMerge(1);
+ w.close();
+ dir.close();
+ }
+
+ // Write point values, one segment with Lucene60, another with SimpleText, then forceMerge with Lucene60
+ public void testDifferentCodecs2() throws Exception {
+ Directory dir = newDirectory();
+ IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
+ iwc.setCodec(Codec.forName("SimpleText"));
+ IndexWriter w = new IndexWriter(dir, iwc);
+ Document doc = new Document();
+ doc.add(new IntPoint("int", 1));
+ w.addDocument(doc);
+ w.close();
+
+ iwc = new IndexWriterConfig(new MockAnalyzer(random()));
+ iwc.setCodec(Codec.forName("Lucene60"));
+ w = new IndexWriter(dir, iwc);
+ doc = new Document();
+ doc.add(new IntPoint("int", 1));
+ w.addDocument(doc);
+
+ w.forceMerge(1);
+ w.close();
+ dir.close();
+ }
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BasePointFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BasePointFormatTestCase.java
index 2dd0b7d1de4..3b19530f432 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BasePointFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BasePointFormatTestCase.java
@@ -1,5 +1,22 @@
package org.apache.lucene.index;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
@@ -17,6 +34,8 @@ import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.PointValues.IntersectVisitor;
import org.apache.lucene.index.PointValues.Relation;
+import org.apache.lucene.search.ExactPointQuery;
+import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.Bits;
@@ -26,23 +45,6 @@ import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.util.StringHelper;
import org.apache.lucene.util.TestUtil;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
/**
* Abstract class to do basic tests for a points format.
* NOTE: This test focuses on the points impl, nothing else.
@@ -820,6 +822,44 @@ public abstract class BasePointFormatTestCase extends BaseIndexFileFormatTestCas
}
}
+ public void testAddIndexes() throws IOException {
+ Directory dir1 = newDirectory();
+ RandomIndexWriter w = new RandomIndexWriter(random(), dir1);
+ Document doc = new Document();
+ doc.add(new IntPoint("int1", 17));
+ w.addDocument(doc);
+ doc = new Document();
+ doc.add(new IntPoint("int2", 42));
+ w.addDocument(doc);
+ w.close();
+
+ // Different field number assigments:
+ Directory dir2 = newDirectory();
+ w = new RandomIndexWriter(random(), dir2);
+ doc = new Document();
+ doc.add(new IntPoint("int2", 42));
+ w.addDocument(doc);
+ doc = new Document();
+ doc.add(new IntPoint("int1", 17));
+ w.addDocument(doc);
+ w.close();
+
+ Directory dir = newDirectory();
+ w = new RandomIndexWriter(random(), dir);
+ w.addIndexes(new Directory[] {dir1, dir2});
+ w.forceMerge(1);
+
+ DirectoryReader r = w.getReader();
+ IndexSearcher s = newSearcher(r);
+ assertEquals(2, s.count(ExactPointQuery.new1DIntExact("int1", 17)));
+ assertEquals(2, s.count(ExactPointQuery.new1DIntExact("int2", 42)));
+ r.close();
+ w.close();
+ dir.close();
+ dir1.close();
+ dir2.close();
+ }
+
private void switchIndex(RandomIndexWriter w, Directory dir, RandomIndexWriter saveW) throws IOException {
if (random().nextBoolean()) {
// Add via readers: