write.lock
could not
- * be obtained)
- * @throws IOException if there is a low-level IO error
- */
- public void setNorm(int doc, String field, float value)
- throws StaleReaderException, CorruptIndexException, LockObtainFailedException, IOException {
- ensureOpen();
- setNorm(doc, field, Similarity.getDefault().encodeNormValue(value));
- }
-
/** Flex API: returns {@link Fields} for this reader.
* This method may return null if the reader has no
* postings.
diff --git a/lucene/src/java/org/apache/lucene/index/MultiNorms.java b/lucene/src/java/org/apache/lucene/index/MultiNorms.java
index 34bd967c73e..1026480fb29 100644
--- a/lucene/src/java/org/apache/lucene/index/MultiNorms.java
+++ b/lucene/src/java/org/apache/lucene/index/MultiNorms.java
@@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.apache.lucene.search.Similarity;
import org.apache.lucene.util.ReaderUtil;
/**
@@ -61,26 +60,24 @@ public class MultiNorms {
ReaderUtil.gatherSubReaders(leaves, r);
int end = 0;
for (IndexReader leaf : leaves) {
+ Fields fields = leaf.fields();
+ boolean hasField = (fields != null && fields.terms(field) != null);
+
int start = end;
- leaf.norms(field, norms, start);
+ byte leafNorms[] = leaf.norms(field);
+ if (leafNorms == null) {
+ if (hasField) { // omitted norms
+ return null;
+ }
+ // doesn't have field, fill bytes
+ leafNorms = new byte[leaf.maxDoc()];
+ Arrays.fill(leafNorms, (byte) 0);
+ }
+
+ System.arraycopy(leafNorms, 0, norms, start, leafNorms.length);
end += leaf.maxDoc();
}
return norms;
}
}
-
- /**
- * Warning: this is heavy! Do not use in a loop, or implement norms()
- * in your own reader with this (you should likely cache the result).
- */
- public static void norms(IndexReader r, String field, byte[] bytes, int offset)
- throws IOException {
- // TODO: optimize more maybe
- byte[] norms = norms(r, field);
- if (norms == null) {
- Arrays.fill(bytes, offset, bytes.length, Similarity.getDefault().encodeNormValue(1.0f));
- } else {
- System.arraycopy(norms, 0, bytes, offset, r.maxDoc());
- }
- }
}
diff --git a/lucene/src/java/org/apache/lucene/index/MultiReader.java b/lucene/src/java/org/apache/lucene/index/MultiReader.java
index 37328d1314a..8a5dca94f22 100644
--- a/lucene/src/java/org/apache/lucene/index/MultiReader.java
+++ b/lucene/src/java/org/apache/lucene/index/MultiReader.java
@@ -304,12 +304,6 @@ public class MultiReader extends IndexReader implements Cloneable {
throw new UnsupportedOperationException("please use MultiNorms.norms, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level norms");
}
- @Override
- public synchronized void norms(String field, byte[] result, int offset)
- throws IOException {
- throw new UnsupportedOperationException("please use MultiNorms.norms, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level norms");
- }
-
@Override
protected void doSetNorm(int n, String field, byte value)
throws CorruptIndexException, IOException {
diff --git a/lucene/src/java/org/apache/lucene/index/NormsWriter.java b/lucene/src/java/org/apache/lucene/index/NormsWriter.java
index 036832297cf..82b4a730e5b 100644
--- a/lucene/src/java/org/apache/lucene/index/NormsWriter.java
+++ b/lucene/src/java/org/apache/lucene/index/NormsWriter.java
@@ -26,7 +26,6 @@ import java.util.List;
import java.util.ArrayList;
import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.search.Similarity;
// TODO FI: norms could actually be stored as doc store
@@ -37,7 +36,6 @@ import org.apache.lucene.search.Similarity;
final class NormsWriter extends InvertedDocEndConsumer {
- private final byte defaultNorm = Similarity.getDefault().encodeNormValue(1.0f);
private FieldInfos fieldInfos;
@Override
public InvertedDocEndConsumerPerThread addThread(DocInverterPerThread docInverterPerThread) {
@@ -62,6 +60,10 @@ final class NormsWriter extends InvertedDocEndConsumer {
final Map
- * WARNING: If you override this method, you should change the default
- * Similarity to your implementation with {@link Similarity#setDefault(Similarity)}.
- * Otherwise, your method may not always be called, especially if you omit norms
- * for some fields.
* @see org.apache.lucene.document.Field#setBoost(float)
* @see org.apache.lucene.util.SmallFloat
*/
diff --git a/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
index e85e4fb4bc5..ffa6238b072 100644
--- a/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
+++ b/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
@@ -43,6 +43,7 @@ import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.Similarity;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Bits;
@@ -216,6 +217,9 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
public void testOptimizeOldIndex() throws Exception {
for(int i=0;i