Index: contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexWriter.java
===================================================================
--- contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexWriter.java (revision 883062)
+++ contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexWriter.java (working copy)
@@ -43,7 +43,6 @@
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermVectorOffsetInfo;
-import org.apache.lucene.search.DefaultSimilarity;
import org.apache.lucene.search.Similarity;
import org.apache.lucene.util.StringHelper;
import org.apache.lucene.util.AttributeImpl;
@@ -202,9 +201,9 @@
byte[] oldNorms = index.getNormsByFieldNameAndDocumentNumber().get(field);
if (oldNorms != null) {
System.arraycopy(oldNorms, 0, norms, 0, oldNorms.length);
- Arrays.fill(norms, oldNorms.length, norms.length, DefaultSimilarity.encodeNorm(1.0f));
+ Arrays.fill(norms, oldNorms.length, norms.length, similarity.encodeNormValue(1.0f));
} else {
- Arrays.fill(norms, 0, norms.length, DefaultSimilarity.encodeNorm(1.0f));
+ Arrays.fill(norms, 0, norms.length, similarity.encodeNormValue(1.0f));
}
normsByFieldNameAndDocumentNumber.put(field, norms);
fieldNames.remove(field);
@@ -212,7 +211,7 @@
for (String field : fieldNames) {
//System.out.println(field);
byte[] norms = new byte[index.getDocumentsByNumber().length + termDocumentInformationFactoryByDocument.size()];
- Arrays.fill(norms, 0, norms.length, DefaultSimilarity.encodeNorm(1.0f));
+ Arrays.fill(norms, 0, norms.length, similarity.encodeNormValue(1.0f));
normsByFieldNameAndDocumentNumber.put(field, norms);
}
fieldNames.clear();
@@ -240,7 +239,7 @@
float norm = eFieldTermDocInfoFactoriesByTermText.getKey().boost;
norm *= document.getDocument().getBoost();
norm *= similarity.lengthNorm(eFieldTermDocInfoFactoriesByTermText.getKey().fieldName, eFieldTermDocInfoFactoriesByTermText.getKey().fieldLength);
- normsByFieldNameAndDocumentNumber.get(eFieldTermDocInfoFactoriesByTermText.getKey().fieldName)[document.getDocumentNumber()] = Similarity.encodeNorm(norm);
+ normsByFieldNameAndDocumentNumber.get(eFieldTermDocInfoFactoriesByTermText.getKey().fieldName)[document.getDocumentNumber()] = similarity.encodeNormValue(norm);
} else {
System.currentTimeMillis();
}
Index: contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
===================================================================
--- contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (revision 883062)
+++ contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (working copy)
@@ -1102,7 +1102,7 @@
float boost = info != null ? info.getBoost() : 1.0f;
FieldInvertState invertState = new FieldInvertState(0, numTokens, numOverlapTokens, 0, boost);
float n = sim.computeNorm(fieldName, invertState);
- byte norm = Similarity.encodeNorm(n);
+ byte norm = sim.encodeNormValue(n);
norms = new byte[] {norm};
// cache it for future reuse
Index: contrib/misc/src/java/org/apache/lucene/index/FieldNormModifier.java
===================================================================
--- contrib/misc/src/java/org/apache/lucene/index/FieldNormModifier.java (revision 883062)
+++ contrib/misc/src/java/org/apache/lucene/index/FieldNormModifier.java (working copy)
@@ -143,7 +143,7 @@
if (sim == null)
reader.setNorm(d, fieldName, Similarity.encodeNorm(1.0f));
else
- reader.setNorm(d, fieldName, Similarity.encodeNorm(sim.lengthNorm(fieldName, termCounts[d])));
+ reader.setNorm(d, fieldName, sim.encodeNormValue(sim.lengthNorm(fieldName, termCounts[d])));
}
}
Index: contrib/misc/src/java/org/apache/lucene/misc/LengthNormModifier.java
===================================================================
--- contrib/misc/src/java/org/apache/lucene/misc/LengthNormModifier.java (revision 834699)
+++ contrib/misc/src/java/org/apache/lucene/misc/LengthNormModifier.java (working copy)
@@ -141,7 +141,7 @@
reader = IndexReader.open(dir, false);
for (int d = 0; d < termCounts.length; d++) {
if (! reader.isDeleted(d)) {
- byte norm = Similarity.encodeNorm(sim.lengthNorm(fieldName, termCounts[d]));
+ byte norm = sim.encodeNormValue(sim.lengthNorm(fieldName, termCounts[d]));
reader.setNorm(d, fieldName, norm);
}
}
Index: contrib/misc/src/test/org/apache/lucene/index/TestFieldNormModifier.java
===================================================================
--- contrib/misc/src/test/org/apache/lucene/index/TestFieldNormModifier.java (revision 883062)
+++ contrib/misc/src/test/org/apache/lucene/index/TestFieldNormModifier.java (working copy)
@@ -44,9 +44,7 @@
public TestFieldNormModifier(String name) {
super(name);
}
-
- public static byte DEFAULT_NORM = Similarity.encodeNorm(1.0f);
-
+
public static int NUM_DOCS = 5;
public Directory store = new RAMDirectory();
Index: contrib/misc/src/test/org/apache/lucene/misc/TestLengthNormModifier.java
===================================================================
--- contrib/misc/src/test/org/apache/lucene/misc/TestLengthNormModifier.java (revision 883062)
+++ contrib/misc/src/test/org/apache/lucene/misc/TestLengthNormModifier.java (working copy)
@@ -47,8 +47,6 @@
public TestLengthNormModifier(String name) {
super(name);
}
-
- public static byte DEFAULT_NORM = Similarity.encodeNorm(1.0f);
public static int NUM_DOCS = 5;
Index: src/java/org/apache/lucene/document/AbstractField.java
===================================================================
--- src/java/org/apache/lucene/document/AbstractField.java (revision 883062)
+++ src/java/org/apache/lucene/document/AbstractField.java (working copy)
@@ -80,13 +80,13 @@
* by the {@link
* org.apache.lucene.search.Similarity#lengthNorm(String,
* int)} and then
- * rounded by {@link org.apache.lucene.search.Similarity#encodeNorm(float)} before it is stored in the
+ * rounded by {@link org.apache.lucene.search.Similarity#encodeNormValue(float)} before it is stored in the
* index. One should attempt to ensure that this product does not overflow
* the range of that encoding.
*
* @see org.apache.lucene.document.Document#setBoost(float)
* @see org.apache.lucene.search.Similarity#computeNorm(String, org.apache.lucene.index.FieldInvertState)
- * @see org.apache.lucene.search.Similarity#encodeNorm(float)
+ * @see org.apache.lucene.search.Similarity#encodeNormValue(float)
*/
public void setBoost(float boost) {
this.boost = boost;
Index: src/java/org/apache/lucene/document/Fieldable.java
===================================================================
--- src/java/org/apache/lucene/document/Fieldable.java (revision 883062)
+++ src/java/org/apache/lucene/document/Fieldable.java (working copy)
@@ -48,13 +48,13 @@
* FieldInvertState)} method, the boost value is multiplied
* by the {@link
* org.apache.lucene.search.Similarity#lengthNorm(String,
- * int)} and then rounded by {@link org.apache.lucene.search.Similarity#encodeNorm(float)} before it is stored in the
+ * int)} and then rounded by {@link org.apache.lucene.search.Similarity#encodeNormValue(float)} before it is stored in the
* index. One should attempt to ensure that this product does not overflow
* the range of that encoding.
*
* @see org.apache.lucene.document.Document#setBoost(float)
* @see org.apache.lucene.search.Similarity#computeNorm(String, FieldInvertState)
- * @see org.apache.lucene.search.Similarity#encodeNorm(float)
+ * @see org.apache.lucene.search.Similarity#encodeNormValue(float)
*/
void setBoost(float boost);
Index: src/java/org/apache/lucene/index/DirectoryReader.java
===================================================================
--- src/java/org/apache/lucene/index/DirectoryReader.java (revision 883062)
+++ src/java/org/apache/lucene/index/DirectoryReader.java (working copy)
@@ -31,7 +31,7 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.FieldSelector;
-import org.apache.lucene.search.DefaultSimilarity;
+import org.apache.lucene.search.Similarity;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.Lock;
@@ -604,7 +604,7 @@
ensureOpen();
byte[] bytes = normsCache.get(field);
if (bytes==null && !hasNorms(field)) {
- Arrays.fill(result, offset, result.length, DefaultSimilarity.encodeNorm(1.0f));
+ Arrays.fill(result, offset, result.length, Similarity.getDefault().encodeNormValue(1.0f));
} else if (bytes != null) { // cache hit
System.arraycopy(bytes, 0, result, offset, maxDoc());
} else {
Index: src/java/org/apache/lucene/index/IndexReader.java
===================================================================
--- src/java/org/apache/lucene/index/IndexReader.java (revision 883062)
+++ src/java/org/apache/lucene/index/IndexReader.java (working copy)
@@ -730,7 +730,7 @@
* this method call will silently do nothing.
*
* @see #norms(String)
- * @see Similarity#decodeNorm(byte)
+ * @see Similarity#decodeNormValue(byte)
* @throws StaleReaderException if the index has changed
* since this reader was opened
* @throws CorruptIndexException if the index is corrupt
@@ -755,7 +755,7 @@
* document.
*
* @see #norms(String)
- * @see Similarity#decodeNorm(byte)
+ * @see Similarity#decodeNormValue(byte)
*
* @throws StaleReaderException if the index has changed
* since this reader was opened
@@ -768,7 +768,7 @@
public void setNorm(int doc, String field, float value)
throws StaleReaderException, CorruptIndexException, LockObtainFailedException, IOException {
ensureOpen();
- setNorm(doc, field, Similarity.encodeNorm(value));
+ setNorm(doc, field, Similarity.getDefault().encodeNormValue(value));
}
/** Returns an enumeration of all the terms in the index. The
Index: src/java/org/apache/lucene/index/MultiReader.java
===================================================================
--- src/java/org/apache/lucene/index/MultiReader.java (revision 883062)
+++ src/java/org/apache/lucene/index/MultiReader.java (working copy)
@@ -29,6 +29,7 @@
import org.apache.lucene.index.DirectoryReader.MultiTermEnum;
import org.apache.lucene.index.DirectoryReader.MultiTermPositions;
import org.apache.lucene.search.DefaultSimilarity;
+import org.apache.lucene.search.Similarity;
/** An IndexReader which reads multiple indexes, appending
* their content. */
@@ -316,7 +317,7 @@
subReaders[i].norms(field, result, offset + starts[i]);
if (bytes==null && !hasNorms(field)) {
- Arrays.fill(result, offset, result.length, DefaultSimilarity.encodeNorm(1.0f));
+ Arrays.fill(result, offset, result.length, Similarity.getDefault().encodeNormValue(1.0f));
} else if (bytes != null) { // cache hit
System.arraycopy(bytes, 0, result, offset, maxDoc());
} else {
Index: src/java/org/apache/lucene/index/NormsWriter.java
===================================================================
--- src/java/org/apache/lucene/index/NormsWriter.java (revision 883062)
+++ src/java/org/apache/lucene/index/NormsWriter.java (working copy)
@@ -37,7 +37,7 @@
final class NormsWriter extends InvertedDocEndConsumer {
- private static final byte defaultNorm = Similarity.encodeNorm(1.0f);
+ private static final byte defaultNorm = Similarity.getDefault().encodeNormValue(1.0f);
private FieldInfos fieldInfos;
@Override
public InvertedDocEndConsumerPerThread addThread(DocInverterPerThread docInverterPerThread) {
Index: src/java/org/apache/lucene/index/NormsWriterPerField.java
===================================================================
--- src/java/org/apache/lucene/index/NormsWriterPerField.java (revision 883062)
+++ src/java/org/apache/lucene/index/NormsWriterPerField.java (working copy)
@@ -71,7 +71,7 @@
norms = ArrayUtil.grow(norms, 1+upto);
}
final float norm = docState.similarity.computeNorm(fieldInfo.name, fieldState);
- norms[upto] = Similarity.encodeNorm(norm);
+ norms[upto] = Similarity.getDefault().encodeNormValue(norm);
docIDs[upto] = docState.docID;
upto++;
}
Index: src/java/org/apache/lucene/index/SegmentReader.java
===================================================================
--- src/java/org/apache/lucene/index/SegmentReader.java (revision 883062)
+++ src/java/org/apache/lucene/index/SegmentReader.java (working copy)
@@ -30,7 +30,7 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.FieldSelector;
-import org.apache.lucene.search.DefaultSimilarity;
+import org.apache.lucene.search.Similarity;
import org.apache.lucene.store.BufferedIndexInput;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
@@ -1022,7 +1022,7 @@
ensureOpen();
Norm norm = norms.get(field);
if (norm == null) {
- Arrays.fill(bytes, offset, bytes.length, DefaultSimilarity.encodeNorm(1.0f));
+ Arrays.fill(bytes, offset, bytes.length, Similarity.getDefault().encodeNormValue(1.0f));
return;
}
Index: src/java/org/apache/lucene/search/MatchAllDocsQuery.java
===================================================================
--- src/java/org/apache/lucene/search/MatchAllDocsQuery.java (revision 883062)
+++ src/java/org/apache/lucene/search/MatchAllDocsQuery.java (working copy)
@@ -70,7 +70,7 @@
@Override
public float score() {
- return norms == null ? score : score * Similarity.decodeNorm(norms[docID()]);
+ return norms == null ? score : score * getSimilarity().decodeNormValue(norms[docID()]);
}
@Override
Index: src/java/org/apache/lucene/search/MultiPhraseQuery.java
===================================================================
--- src/java/org/apache/lucene/search/MultiPhraseQuery.java (revision 883062)
+++ src/java/org/apache/lucene/search/MultiPhraseQuery.java (working copy)
@@ -238,7 +238,7 @@
Explanation fieldNormExpl = new Explanation();
byte[] fieldNorms = reader.norms(field);
float fieldNorm =
- fieldNorms!=null ? Similarity.decodeNorm(fieldNorms[doc]) : 1.0f;
+ fieldNorms!=null ? similarity.decodeNormValue(fieldNorms[doc]) : 1.0f;
fieldNormExpl.setValue(fieldNorm);
fieldNormExpl.setDescription("fieldNorm(field="+field+", doc="+doc+")");
fieldExpl.addDetail(fieldNormExpl);
Index: src/java/org/apache/lucene/search/PhraseQuery.java
===================================================================
--- src/java/org/apache/lucene/search/PhraseQuery.java (revision 883062)
+++ src/java/org/apache/lucene/search/PhraseQuery.java (working copy)
@@ -108,7 +108,7 @@
}
private class PhraseWeight extends Weight {
- private Similarity similarity;
+ private final Similarity similarity;
private float value;
private float idf;
private float queryNorm;
@@ -232,7 +232,7 @@
Explanation fieldNormExpl = new Explanation();
byte[] fieldNorms = reader.norms(field);
float fieldNorm =
- fieldNorms!=null ? Similarity.decodeNorm(fieldNorms[doc]) : 1.0f;
+ fieldNorms!=null ? similarity.decodeNormValue(fieldNorms[doc]) : 1.0f;
fieldNormExpl.setValue(fieldNorm);
fieldNormExpl.setDescription("fieldNorm(field="+field+", doc="+doc+")");
fieldExpl.addDetail(fieldNormExpl);
Index: src/java/org/apache/lucene/search/PhraseScorer.java
===================================================================
--- src/java/org/apache/lucene/search/PhraseScorer.java (revision 883062)
+++ src/java/org/apache/lucene/search/PhraseScorer.java (working copy)
@@ -110,7 +110,7 @@
public float score() throws IOException {
//System.out.println("scoring " + first.doc);
float raw = getSimilarity().tf(freq) * value; // raw score
- return norms == null ? raw : raw * Similarity.decodeNorm(norms[first.doc]); // normalize
+ return norms == null ? raw : raw * getSimilarity().decodeNormValue(norms[first.doc]); // normalize
}
@Override
Index: src/java/org/apache/lucene/search/Scorer.java
===================================================================
--- src/java/org/apache/lucene/search/Scorer.java (revision 883062)
+++ src/java/org/apache/lucene/search/Scorer.java (working copy)
@@ -38,7 +38,7 @@
* with these scores.
*/
public abstract class Scorer extends DocIdSetIterator {
- private Similarity similarity;
+ private final Similarity similarity;
/** Constructs a Scorer.
* @param similarity The Similarity implementation used by this scorer.
Index: src/java/org/apache/lucene/search/Similarity.java
===================================================================
--- src/java/org/apache/lucene/search/Similarity.java (revision 883062)
+++ src/java/org/apache/lucene/search/Similarity.java (working copy)
@@ -26,7 +26,6 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.Collection;
-import java.util.IdentityHashMap;
/**
@@ -498,11 +497,11 @@
*
*
*
- * However the resulted norm value is {@link #encodeNorm(float) encoded} as a single byte
+ * However the resulted norm value is {@link #encodeNormValue(float) encoded} as a single byte
* before being stored.
* At search time, the norm byte value is read from the index
* {@link org.apache.lucene.store.Directory directory} and
- * {@link #decodeNorm(byte) decoded} back to a float norm value.
+ * {@link #decodeNormValue(byte) decoded} back to a float norm value.
* This encoding/decoding, while reducing index size, comes with the price of
* precision loss - it is not guaranteed that decode(encode(x)) = x.
* For instance, decode(encode(0.89)) = 0.75.
@@ -563,16 +562,30 @@
NORM_TABLE[i] = SmallFloat.byte315ToFloat((byte)i);
}
- /** Decodes a normalization factor stored in an index.
- * @see #encodeNorm(float)
+ /**
+ * Decodes a normalization factor stored in an index.
+ * @see #decodeNormValue(float)
+ * @deprecated Use decodeNormValue instead.
*/
+ @Deprecated
public static float decodeNorm(byte b) {
return NORM_TABLE[b & 0xFF]; // & 0xFF maps negative bytes to positive above 127
}
+ /** Decodes a normalization factor stored in an index.
+ * @see #encodeNormValue(float)
+ */
+ public float decodeNormValue(byte b) {
+ return NORM_TABLE[b & 0xFF]; // & 0xFF maps negative bytes to positive above 127
+ }
+
/** Returns a table for decoding normalization bytes.
- * @see #encodeNorm(float)
+ * @see #encodeNormValue(float)
+ * @see #decodeNormValue(byte)
+ *
+ * @deprecated Use instance methods for encoding/decoding norm values to enable customization.
*/
+ @Deprecated
public static float[] getNormDecoder() {
return NORM_TABLE;
}
@@ -612,7 +625,7 @@
*
Note that the return values are computed under * {@link org.apache.lucene.index.IndexWriter#addDocument(org.apache.lucene.document.Document)} * and then stored using - * {@link #encodeNorm(float)}. + * {@link #encodeNormValue(float)}. * Thus they have limited precision, and documents * must be re-indexed if this method is altered. * @@ -654,6 +667,19 @@ * @see org.apache.lucene.document.Field#setBoost(float) * @see org.apache.lucene.util.SmallFloat */ + public byte encodeNormValue(float f) { + return SmallFloat.floatToByte315(f); + } + + /** + * Static accessor kept for backwards compability reason, use encodeNormValue instead. + * @param f norm-value to encode + * @return byte representing the given float + * @deprecated Use encodeNormValue instead. + * + * @see #encodeNormValue(float) + */ + @Deprecated public static byte encodeNorm(float f) { return SmallFloat.floatToByte315(f); } Index: src/java/org/apache/lucene/search/spans/SpanScorer.java =================================================================== --- src/java/org/apache/lucene/search/spans/SpanScorer.java (revision 883062) +++ src/java/org/apache/lucene/search/spans/SpanScorer.java (working copy) @@ -95,7 +95,7 @@ @Override public float score() throws IOException { float raw = getSimilarity().tf(freq) * value; // raw score - return norms == null? raw : raw * Similarity.decodeNorm(norms[doc]); // normalize + return norms == null? raw : raw * getSimilarity().decodeNormValue(norms[doc]); // normalize } /** This method is no longer an official member of {@link Scorer}, Index: src/java/org/apache/lucene/search/spans/SpanWeight.java =================================================================== --- src/java/org/apache/lucene/search/spans/SpanWeight.java (revision 883062) +++ src/java/org/apache/lucene/search/spans/SpanWeight.java (working copy) @@ -118,7 +118,7 @@ Explanation fieldNormExpl = new Explanation(); byte[] fieldNorms = reader.norms(field); float fieldNorm = - fieldNorms!=null ? Similarity.decodeNorm(fieldNorms[doc]) : 1.0f; + fieldNorms!=null ? similarity.decodeNormValue(fieldNorms[doc]) : 1.0f; fieldNormExpl.setValue(fieldNorm); fieldNormExpl.setDescription("fieldNorm(field="+field+", doc="+doc+")"); fieldExpl.addDetail(fieldNormExpl); Index: src/java/org/apache/lucene/search/TermQuery.java =================================================================== --- src/java/org/apache/lucene/search/TermQuery.java (revision 883062) +++ src/java/org/apache/lucene/search/TermQuery.java (working copy) @@ -33,7 +33,7 @@ private Term term; private class TermWeight extends Weight { - private Similarity similarity; + private final Similarity similarity; private float value; private float idf; private float queryNorm; @@ -135,7 +135,7 @@ Explanation fieldNormExpl = new Explanation(); byte[] fieldNorms = reader.norms(field); float fieldNorm = - fieldNorms!=null ? Similarity.decodeNorm(fieldNorms[doc]) : 1.0f; + fieldNorms!=null ? similarity.decodeNormValue(fieldNorms[doc]) : 1.0f; fieldNormExpl.setValue(fieldNorm); fieldNormExpl.setDescription("fieldNorm(field="+field+", doc="+doc+")"); fieldExpl.addDetail(fieldNormExpl); Index: src/java/org/apache/lucene/search/TermScorer.java =================================================================== --- src/java/org/apache/lucene/search/TermScorer.java (revision 883062) +++ src/java/org/apache/lucene/search/TermScorer.java (working copy) @@ -25,7 +25,7 @@ */ final class TermScorer extends Scorer { - private static final float[] SIM_NORM_DECODER = Similarity.getNormDecoder(); +// private static final float[] SIM_NORM_DECODER = Similarity.getNormDecoder(); private Weight weight; private TermDocs termDocs; @@ -56,6 +56,7 @@ */ TermScorer(Weight weight, TermDocs td, Similarity similarity, byte[] norms) { super(similarity); + this.weight = weight; this.termDocs = td; this.norms = norms; @@ -127,7 +128,7 @@ ? scoreCache[f] // cache hit : getSimilarity().tf(f)*weightValue; // cache miss - return norms == null ? raw : raw * SIM_NORM_DECODER[norms[doc] & 0xFF]; // normalize for field + return norms == null ? raw : raw * getSimilarity().decodeNormValue(norms[doc]); // normalize for field } /** Index: src/test/org/apache/lucene/index/TestIndexReader.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexReader.java (revision 883062) +++ src/test/org/apache/lucene/index/TestIndexReader.java (working copy) @@ -511,7 +511,7 @@ // is open against the index: public void testWritingNorms() throws IOException { - String tempDir = System.getProperty("tempDir"); + String tempDir = "target/test"; if (tempDir == null) throw new IOException("tempDir undefined, cannot run test"); Index: src/test/org/apache/lucene/index/TestIndexReaderClone.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexReaderClone.java (revision 883062) +++ src/test/org/apache/lucene/index/TestIndexReaderClone.java (working copy) @@ -273,13 +273,13 @@ * @throws Exception */ private void performDefaultTests(IndexReader r1) throws Exception { - float norm1 = Similarity.decodeNorm(r1.norms("field1")[4]); + float norm1 = Similarity.getDefault().decodeNormValue(r1.norms("field1")[4]); IndexReader pr1Clone = (IndexReader) r1.clone(); pr1Clone.deleteDocument(10); pr1Clone.setNorm(4, "field1", 0.5f); - assertTrue(Similarity.decodeNorm(r1.norms("field1")[4]) == norm1); - assertTrue(Similarity.decodeNorm(pr1Clone.norms("field1")[4]) != norm1); + assertTrue(Similarity.getDefault().decodeNormValue(r1.norms("field1")[4]) == norm1); + assertTrue(Similarity.getDefault().decodeNormValue(pr1Clone.norms("field1")[4]) != norm1); assertTrue(!r1.isDeleted(10)); assertTrue(pr1Clone.isDeleted(10)); @@ -426,7 +426,7 @@ TestIndexReaderReopen.createIndex(dir1, false); IndexReader orig = IndexReader.open(dir1, false); orig.setNorm(1, "field1", 17.0f); - final byte encoded = Similarity.encodeNorm(17.0f); + final byte encoded = Similarity.getDefault().encodeNormValue(17.0f); assertEquals(encoded, orig.norms("field1")[1]); // the cloned segmentreader should have 2 references, 1 to itself, and 1 to Index: src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java (revision 883062) +++ src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java (working copy) @@ -216,7 +216,8 @@ } // norm values should be different - assertTrue(Similarity.decodeNorm(segmentReader3C.norms("field1")[5]) != Similarity.decodeNorm(segmentReader4C.norms("field1")[5])); + assertTrue(Similarity.getDefault().decodeNormValue(segmentReader3C.norms("field1")[5]) + != Similarity.getDefault().decodeNormValue(segmentReader4C.norms("field1")[5])); Norm reader4CCNorm = segmentReader4C.norms.get("field1"); assertEquals(3, reader3CCNorm.bytesRef().refCount()); assertEquals(1, reader4CCNorm.bytesRef().refCount()); @@ -283,7 +284,7 @@ assertEquals("number of norms mismatches", numDocNorms, b.length); ArrayList storedNorms = (i == 1 ? modifiedNorms : norms); for (int j = 0; j < b.length; j++) { - float norm = Similarity.decodeNorm(b[j]); + float norm = Similarity.getDefault().decodeNormValue(b[j]); float norm1 = ((Float) storedNorms.get(j)).floatValue(); assertEquals("stored norm value of " + field + " for doc " + j + " is " + norm + " - a mismatch!", norm, norm1, 0.000001); @@ -321,7 +322,8 @@ private float nextNorm() { float norm = lastNorm + normDelta; do { - float norm1 = Similarity.decodeNorm(Similarity.encodeNorm(norm)); + float norm1 = Similarity.getDefault().decodeNormValue( + Similarity.getDefault().encodeNormValue(norm)); if (norm1 > lastNorm) { // System.out.println(norm1+" > "+lastNorm); norm = norm1; Index: src/test/org/apache/lucene/index/TestNorms.java =================================================================== --- src/test/org/apache/lucene/index/TestNorms.java (revision 883062) +++ src/test/org/apache/lucene/index/TestNorms.java (working copy) @@ -189,7 +189,7 @@ assertEquals("number of norms mismatches",numDocNorms,b.length); ArrayList storedNorms = (i==1 ? modifiedNorms : norms); for (int j = 0; j < b.length; j++) { - float norm = Similarity.decodeNorm(b[j]); + float norm = similarityOne.decodeNormValue(b[j]); float norm1 = ((Float)storedNorms.get(j)).floatValue(); assertEquals("stored norm value of "+field+" for doc "+j+" is "+norm+" - a mismatch!", norm, norm1, 0.000001); } @@ -224,7 +224,7 @@ private float nextNorm() { float norm = lastNorm + normDelta; do { - float norm1 = Similarity.decodeNorm(Similarity.encodeNorm(norm)); + float norm1 = similarityOne.decodeNormValue(similarityOne.encodeNormValue(norm)); if (norm1 > lastNorm) { //System.out.println(norm1+" > "+lastNorm); norm = norm1; Index: src/test/org/apache/lucene/index/TestSegmentReader.java =================================================================== --- src/test/org/apache/lucene/index/TestSegmentReader.java (revision 883062) +++ src/test/org/apache/lucene/index/TestSegmentReader.java (working copy) @@ -26,7 +26,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Fieldable; -import org.apache.lucene.search.DefaultSimilarity; +import org.apache.lucene.search.Similarity; import org.apache.lucene.store.RAMDirectory; public class TestSegmentReader extends LuceneTestCase { @@ -167,7 +167,7 @@ if (!reader.hasNorms(f.name())) { // test for fake norms of 1.0 or null depending on the flag byte [] norms = reader.norms(f.name()); - byte norm1 = DefaultSimilarity.encodeNorm(1.0f); + byte norm1 = Similarity.getDefault().encodeNormValue(1.0f); assertNull(norms); norms = new byte[reader.maxDoc()]; reader.norms(f.name(),norms, 0);