| Index: solr/src/test/org/apache/solr/search/function/TestFunctionQuery.java
|
| ===================================================================
|
| --- solr/src/test/org/apache/solr/search/function/TestFunctionQuery.java (revision 1068958)
|
| +++ solr/src/test/org/apache/solr/search/function/TestFunctionQuery.java (working copy)
|
| @@ -299,7 +299,7 @@
|
| state.setBoost(1.0f); |
| state.setLength(4); |
| assertQ(req("fl","*,score","q", "{!func}norm(a_t)", "fq","id:2"), |
| - "//float[@name='score']='" + similarity.computeNorm("a_t",state) + "'"); // sqrt(4)==2 and is exactly representable when quantized to a byte |
| + "//float[@name='score']='" + similarity.computeNorm(state) + "'"); // sqrt(4)==2 and is exactly representable when quantized to a byte |
| |
| // test that ord and rord are working on a global index basis, not just |
| // at the segment level (since Lucene 2.9 has switched to per-segment searching) |
| Index: lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java (revision 1068958)
|
| +++ lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java (working copy)
|
| @@ -299,14 +299,14 @@
|
| // must be static for weight serialization tests |
| static class BoostingSimilarity extends DefaultSimilarity { |
| |
| - @Override public float scorePayload(int docId, String fieldName, int start, int end, byte[] payload, int offset, int length) { |
| + @Override public float scorePayload(int docId, int start, int end, byte[] payload, int offset, int length) { |
| //we know it is size 4 here, so ignore the offset/length |
| return payload[offset]; |
| } |
| //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| //Make everything else 1 so we see the effect of the payload |
| //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| - @Override public float computeNorm(String fieldName, FieldInvertState state) { |
| + @Override public float computeNorm(FieldInvertState state) { |
| return state.getBoost(); |
| } |
| |
| Index: lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java (revision 1068958)
|
| +++ lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java (working copy)
|
| @@ -287,7 +287,7 @@
|
| |
| // TODO: Remove warning after API has been finalized |
| @Override |
| - public float scorePayload(int docId, String fieldName, int start, int end, byte[] payload, int offset, int length) { |
| + public float scorePayload(int docId, int start, int end, byte[] payload, int offset, int length) { |
| //we know it is size 4 here, so ignore the offset/length |
| return payload[offset]; |
| } |
| @@ -296,7 +296,7 @@
|
| //Make everything else 1 so we see the effect of the payload |
| //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| @Override |
| - public float computeNorm(String fieldName, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| return state.getBoost(); |
| } |
| |
| Index: lucene/src/test/org/apache/lucene/search/JustCompileSearch.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/search/JustCompileSearch.java (revision 1068958)
|
| +++ lucene/src/test/org/apache/lucene/search/JustCompileSearch.java (working copy)
|
| @@ -248,7 +248,7 @@
|
| } |
| |
| @Override |
| - public float computeNorm(String fieldName, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| throw new UnsupportedOperationException(UNSUPPORTED_MSG); |
| } |
| |
| Index: lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java (revision 1068958)
|
| +++ lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java (working copy)
|
| @@ -62,7 +62,7 @@
|
| } |
| |
| @Override |
| - public float computeNorm(String fieldName, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| // Disable length norm |
| return state.getBoost(); |
| } |
| Index: lucene/src/test/org/apache/lucene/search/TestSimilarity.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/search/TestSimilarity.java (revision 1068958)
|
| +++ lucene/src/test/org/apache/lucene/search/TestSimilarity.java (working copy)
|
| @@ -40,7 +40,7 @@
|
| public class TestSimilarity extends LuceneTestCase { |
| |
| public static class SimpleSimilarity extends Similarity implements SimilarityProvider { |
| - @Override public float computeNorm(String field, FieldInvertState state) { return state.getBoost(); } |
| + @Override public float computeNorm(FieldInvertState state) { return state.getBoost(); } |
| @Override public float tf(float freq) { return freq; } |
| @Override public float sloppyFreq(int distance) { return 2.0f; } |
| @Override public float idf(int docFreq, int numDocs) { return 1.0f; } |
| Index: lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java (revision 1068958)
|
| +++ lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java (working copy)
|
| @@ -107,7 +107,7 @@
|
| |
| private class Sim1 extends Similarity { |
| @Override |
| - public float computeNorm(String field, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| return 1f; |
| } |
| |
| @@ -129,7 +129,7 @@
|
| |
| private class Sim2 extends Similarity { |
| @Override |
| - public float computeNorm(String field, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| return 10f; |
| } |
| |
| Index: lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java (revision 1068958)
|
| +++ lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java (working copy)
|
| @@ -43,7 +43,7 @@
|
| |
| private class SimilarityOne extends DefaultSimilarity { |
| @Override |
| - public float computeNorm(String fieldName, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| // diable length norm |
| return state.getBoost(); |
| } |
| Index: lucene/src/test/org/apache/lucene/index/TestMaxTermFrequency.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestMaxTermFrequency.java (revision 1068958)
|
| +++ lucene/src/test/org/apache/lucene/index/TestMaxTermFrequency.java (working copy)
|
| @@ -109,7 +109,7 @@
|
| } |
| |
| @Override |
| - public float computeNorm(String field, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| return (float) state.getMaxTermFrequency(); |
| } |
| } |
| Index: lucene/src/test/org/apache/lucene/index/TestOmitTf.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestOmitTf.java (revision 1068958)
|
| +++ lucene/src/test/org/apache/lucene/index/TestOmitTf.java (working copy)
|
| @@ -36,7 +36,7 @@
|
| public class TestOmitTf extends LuceneTestCase { |
| |
| public static class SimpleSimilarity extends Similarity implements SimilarityProvider { |
| - @Override public float computeNorm(String field, FieldInvertState state) { return state.getBoost(); } |
| + @Override public float computeNorm(FieldInvertState state) { return state.getBoost(); } |
| @Override public float tf(float freq) { return freq; } |
| @Override public float sloppyFreq(int distance) { return 2.0f; } |
| @Override public float idf(int docFreq, int numDocs) { return 1.0f; } |
| Index: lucene/src/test/org/apache/lucene/index/TestNorms.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestNorms.java (revision 1068958)
|
| +++ lucene/src/test/org/apache/lucene/index/TestNorms.java (working copy)
|
| @@ -42,7 +42,7 @@
|
| |
| private class SimilarityOne extends DefaultSimilarity { |
| @Override |
| - public float computeNorm(String fieldName, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| // Disable length norm |
| return state.getBoost(); |
| } |
| @@ -252,7 +252,7 @@
|
| } |
| |
| @Override |
| - public float computeNorm(String field, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| return (float) state.getLength(); |
| } |
| } |
| Index: lucene/src/java/org/apache/lucene/search/Similarity.java
|
| ===================================================================
|
| --- lucene/src/java/org/apache/lucene/search/Similarity.java (revision 1068958)
|
| +++ lucene/src/java/org/apache/lucene/search/Similarity.java (working copy)
|
| @@ -561,49 +561,13 @@
|
| * Thus they have limited precision, and documents |
| * must be re-indexed if this method is altered. |
| * |
| - * <p>For backward compatibility this method by default calls |
| - * {@link #lengthNorm(String, int)} passing |
| - * {@link FieldInvertState#getLength()} as the second argument, and |
| - * then multiplies this value by {@link FieldInvertState#getBoost()}.</p> |
| - * |
| * @lucene.experimental |
| * |
| - * @param field field name |
| * @param state current processing state for this field |
| * @return the calculated float norm |
| */ |
| - public abstract float computeNorm(String field, FieldInvertState state); |
| + public abstract float computeNorm(FieldInvertState state); |
| |
| - /** Computes the normalization value for a field given the total number of |
| - * terms contained in a field. These values, together with field boosts, are |
| - * stored in an index and multipled into scores for hits on each field by the |
| - * search code. |
| - * |
| - * <p>Matches in longer fields are less precise, so implementations of this |
| - * method usually return smaller values when <code>numTokens</code> is large, |
| - * and larger values when <code>numTokens</code> is small. |
| - * |
| - * <p>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 #encodeNormValue(float)}. |
| - * Thus they have limited precision, and documents |
| - * must be re-indexed if this method is altered. |
| - * |
| - * @param fieldName the name of the field |
| - * @param numTokens the total number of tokens contained in fields named |
| - * <i>fieldName</i> of <i>doc</i>. |
| - * @return a normalization factor for hits on this field of this document |
| - * |
| - * @see org.apache.lucene.document.Field#setBoost(float) |
| - * |
| - * @deprecated Please override computeNorm instead |
| - */ |
| - @Deprecated |
| - public final float lengthNorm(String fieldName, int numTokens) { |
| - throw new UnsupportedOperationException("please use computeNorm instead"); |
| - } |
| - |
| /** Encodes a normalization factor for storage in an index. |
| * |
| * <p>The encoding uses a three-bit mantissa, a five-bit exponent, and |
| @@ -781,7 +745,6 @@
|
| * The default implementation returns 1. |
| * |
| * @param docId The docId currently being scored. If this value is {@link #NO_DOC_ID_PROVIDED}, then it should be assumed that the PayloadQuery implementation does not provide document information |
| - * @param fieldName The fieldName of the term this payload belongs to |
| * @param start The start position of the payload |
| * @param end The end position of the payload |
| * @param payload The payload byte array to be scored |
| @@ -791,7 +754,7 @@
|
| * |
| */ |
| // TODO: maybe switch this API to BytesRef? |
| - public float scorePayload(int docId, String fieldName, int start, int end, byte [] payload, int offset, int length) |
| + public float scorePayload(int docId, int start, int end, byte [] payload, int offset, int length) |
| { |
| return 1; |
| } |
| Index: lucene/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java
|
| ===================================================================
|
| --- lucene/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java (revision 1068958)
|
| +++ lucene/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java (working copy)
|
| @@ -192,7 +192,7 @@
|
| protected void processPayloads(Collection<byte[]> payLoads, int start, int end) { |
| for (final byte[] thePayload : payLoads) { |
| payloadScore = function.currentScore(doc, fieldName, start, end, |
| - payloadsSeen, payloadScore, similarity.scorePayload(doc, fieldName, |
| + payloadsSeen, payloadScore, similarity.scorePayload(doc, |
| spans.start(), spans.end(), thePayload, 0, thePayload.length)); |
| ++payloadsSeen; |
| } |
| Index: lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java
|
| ===================================================================
|
| --- lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java (revision 1068958)
|
| +++ lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java (working copy)
|
| @@ -41,7 +41,7 @@
|
| * {@link org.apache.lucene.index.Term} occurs. |
| * <p> |
| * In order to take advantage of this, you must override |
| - * {@link org.apache.lucene.search.Similarity#scorePayload(int, String, int, int, byte[],int,int)} |
| + * {@link org.apache.lucene.search.Similarity#scorePayload(int, int, int, byte[],int,int)} |
| * which returns 1 by default. |
| * <p> |
| * Payload scores are aggregated using a pluggable {@link PayloadFunction}. |
| @@ -119,14 +119,14 @@
|
| if (payload != null) { |
| payloadScore = function.currentScore(doc, term.field(), |
| spans.start(), spans.end(), payloadsSeen, payloadScore, |
| - similarity.scorePayload(doc, term.field(), spans.start(), |
| + similarity.scorePayload(doc, spans.start(), |
| spans.end(), payload.bytes, |
| payload.offset, |
| payload.length)); |
| } else { |
| payloadScore = function.currentScore(doc, term.field(), |
| spans.start(), spans.end(), payloadsSeen, payloadScore, |
| - similarity.scorePayload(doc, term.field(), spans.start(), |
| + similarity.scorePayload(doc, spans.start(), |
| spans.end(), null, |
| 0, |
| 0)); |
| Index: lucene/src/java/org/apache/lucene/search/DefaultSimilarity.java
|
| ===================================================================
|
| --- lucene/src/java/org/apache/lucene/search/DefaultSimilarity.java (revision 1068958)
|
| +++ lucene/src/java/org/apache/lucene/search/DefaultSimilarity.java (working copy)
|
| @@ -31,7 +31,7 @@
|
| * |
| * @lucene.experimental */ |
| @Override |
| - public float computeNorm(String field, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| final int numTerms; |
| if (discountOverlaps) |
| numTerms = state.getLength() - state.getNumOverlap(); |
| Index: lucene/src/java/org/apache/lucene/index/NormsWriterPerField.java
|
| ===================================================================
|
| --- lucene/src/java/org/apache/lucene/index/NormsWriterPerField.java (revision 1068958)
|
| +++ lucene/src/java/org/apache/lucene/index/NormsWriterPerField.java (working copy)
|
| @@ -74,7 +74,7 @@
|
| assert norms.length == upto; |
| norms = ArrayUtil.grow(norms, 1+upto); |
| } |
| - final float norm = similarity.computeNorm(fieldInfo.name, fieldState); |
| + final float norm = similarity.computeNorm(fieldState); |
| norms[upto] = similarity.encodeNormValue(norm); |
| docIDs[upto] = docState.docID; |
| upto++; |
| Index: lucene/src/java/org/apache/lucene/index/IndexReader.java
|
| ===================================================================
|
| --- lucene/src/java/org/apache/lucene/index/IndexReader.java (revision 1068958)
|
| +++ lucene/src/java/org/apache/lucene/index/IndexReader.java (working copy)
|
| @@ -1004,8 +1004,8 @@
|
| |
| /** Expert: Resets the normalization factor for the named field of the named |
| * document. The norm represents the product of the field's {@link |
| - * org.apache.lucene.document.Fieldable#setBoost(float) boost} and its {@link Similarity#lengthNorm(String, |
| - * int) length normalization}. Thus, to preserve the length normalization |
| + * org.apache.lucene.document.Fieldable#setBoost(float) boost} and its |
| + * length normalization}. Thus, to preserve the length normalization |
| * values when resetting this, one should base the new value upon the old. |
| * |
| * <b>NOTE:</b> If this field does not store norms, then |
| Index: lucene/src/java/org/apache/lucene/document/AbstractField.java
|
| ===================================================================
|
| --- lucene/src/java/org/apache/lucene/document/AbstractField.java (revision 1068958)
|
| +++ lucene/src/java/org/apache/lucene/document/AbstractField.java (working copy)
|
| @@ -76,17 +76,14 @@
|
| * name, all such values are multiplied together. This product is then |
| * used to compute the norm factor for the field. By |
| * default, in the {@link |
| - * org.apache.lucene.search.Similarity#computeNorm(String, |
| - * FieldInvertState)} method, the boost value is multiplied |
| - * by the {@link |
| - * org.apache.lucene.search.Similarity#lengthNorm(String, |
| - * int)} and then |
| + * org.apache.lucene.search.Similarity#computeNorm(FieldInvertState)} method, the boost value is multiplied |
| + * by the length normalization factor 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#computeNorm(FieldInvertState) |
| * @see org.apache.lucene.search.Similarity#encodeNormValue(float) |
| */ |
| public void setBoost(float boost) { |
| Index: lucene/src/java/org/apache/lucene/document/Fieldable.java
|
| ===================================================================
|
| --- lucene/src/java/org/apache/lucene/document/Fieldable.java (revision 1068958)
|
| +++ lucene/src/java/org/apache/lucene/document/Fieldable.java (working copy)
|
| @@ -43,16 +43,14 @@
|
| * name, all such values are multiplied together. This product is then |
| * used to compute the norm factor for the field. By |
| * default, in the {@link |
| - * org.apache.lucene.search.Similarity#computeNorm(String, |
| - * 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#encodeNormValue(float)} before it is stored in the |
| + * org.apache.lucene.search.Similarity#computeNorm(FieldInvertState)} method, the boost value is multiplied |
| + * by the length normalization factor |
| + * 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#computeNorm(FieldInvertState) |
| * @see org.apache.lucene.search.Similarity#encodeNormValue(float) |
| */ |
| void setBoost(float boost); |
| Index: lucene/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexWriter.java
|
| ===================================================================
|
| --- lucene/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexWriter.java (revision 1068958)
|
| +++ lucene/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexWriter.java (working copy)
|
| @@ -241,7 +241,7 @@
|
| final FieldInvertState invertState = new FieldInvertState(); |
| invertState.setBoost(eFieldTermDocInfoFactoriesByTermText.getKey().boost * document.getDocument().getBoost()); |
| invertState.setLength(eFieldTermDocInfoFactoriesByTermText.getKey().fieldLength); |
| - final float norm = similarityProvider.get(fieldName).computeNorm(fieldName, invertState); |
| + final float norm = similarityProvider.get(fieldName).computeNorm(invertState); |
| normsByFieldNameAndDocumentNumber.get(fieldName)[document.getDocumentNumber()] = similarityProvider.get(fieldName).encodeNormValue(norm); |
| } else { |
| System.currentTimeMillis(); |
| Index: lucene/contrib/misc/src/test/org/apache/lucene/index/TestFieldNormModifier.java
|
| ===================================================================
|
| --- lucene/contrib/misc/src/test/org/apache/lucene/index/TestFieldNormModifier.java (revision 1068958)
|
| +++ lucene/contrib/misc/src/test/org/apache/lucene/index/TestFieldNormModifier.java (working copy)
|
| @@ -44,7 +44,7 @@
|
| /** inverts the normal notion of lengthNorm */ |
| public static SimilarityProvider s = new DefaultSimilarity() { |
| @Override |
| - public float computeNorm(String fieldName, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| return state.getBoost() * (discountOverlaps ? state.getLength() - state.getNumOverlap() : state.getLength()); |
| } |
| }; |
| Index: lucene/contrib/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java
|
| ===================================================================
|
| --- lucene/contrib/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java (revision 1068958)
|
| +++ lucene/contrib/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java (working copy)
|
| @@ -20,6 +20,7 @@
|
| |
| import org.apache.lucene.search.DefaultSimilarity; |
| import org.apache.lucene.search.Similarity; |
| +import org.apache.lucene.search.SimilarityProvider; |
| import org.apache.lucene.util.LuceneTestCase; |
| import org.apache.lucene.index.FieldInvertState; |
| |
| @@ -30,8 +31,8 @@
|
| |
| public void testSweetSpotComputeNorm() { |
| |
| - SweetSpotSimilarity ss = new SweetSpotSimilarity(); |
| - ss.setLengthNormFactors(1,1,0.5f); |
| + final SweetSpotSimilarity ss = new SweetSpotSimilarity(); |
| + ss.setLengthNormFactors(1,1,0.5f,true); |
| |
| Similarity d = new DefaultSimilarity(); |
| Similarity s = ss; |
| @@ -43,28 +44,28 @@
|
| for (int i = 1; i < 1000; i++) { |
| invertState.setLength(i); |
| assertEquals("base case: i="+i, |
| - d.computeNorm("foo", invertState), |
| - s.computeNorm("foo", invertState), |
| + d.computeNorm(invertState), |
| + s.computeNorm(invertState), |
| 0.0f); |
| } |
| |
| // make a sweet spot |
| |
| - ss.setLengthNormFactors(3,10,0.5f); |
| + ss.setLengthNormFactors(3,10,0.5f,true); |
| |
| for (int i = 3; i <=10; i++) { |
| invertState.setLength(i); |
| assertEquals("3,10: spot i="+i, |
| 1.0f, |
| - s.computeNorm("foo", invertState), |
| + s.computeNorm(invertState), |
| 0.0f); |
| } |
| |
| for (int i = 10; i < 1000; i++) { |
| invertState.setLength(i-9); |
| - final float normD = d.computeNorm("foo", invertState); |
| + final float normD = d.computeNorm(invertState); |
| invertState.setLength(i); |
| - final float normS = s.computeNorm("foo", invertState); |
| + final float normS = s.computeNorm(invertState); |
| assertEquals("3,10: 10<x : i="+i, |
| normD, |
| normS, |
| @@ -74,22 +75,42 @@
|
| |
| // seperate sweet spot for certain fields |
| |
| - ss.setLengthNormFactors("bar",8,13, 0.5f, false); |
| - ss.setLengthNormFactors("yak",6,9, 0.5f, false); |
| - |
| + final SweetSpotSimilarity ssBar = new SweetSpotSimilarity(); |
| + ssBar.setLengthNormFactors(8,13, 0.5f, false); |
| + final SweetSpotSimilarity ssYak = new SweetSpotSimilarity(); |
| + ssYak.setLengthNormFactors(6,9, 0.5f, false); |
| + final SweetSpotSimilarity ssA = new SweetSpotSimilarity(); |
| + ssA.setLengthNormFactors(5,8,0.5f, false); |
| + final SweetSpotSimilarity ssB = new SweetSpotSimilarity(); |
| + ssB.setLengthNormFactors(5,8,0.1f, false); |
| + |
| + SimilarityProvider sp = new SweetSpotSimilarity() { |
| + public Similarity get(String field) { |
| + if (field.equals("bar")) |
| + return ssBar; |
| + else if (field.equals("yak")) |
| + return ssYak; |
| + else if (field.equals("a")) |
| + return ssA; |
| + else if (field.equals("b")) |
| + return ssB; |
| + else |
| + return ss; |
| + } |
| + }; |
| |
| for (int i = 3; i <=10; i++) { |
| invertState.setLength(i); |
| assertEquals("f: 3,10: spot i="+i, |
| 1.0f, |
| - s.computeNorm("foo", invertState), |
| + sp.get("foo").computeNorm(invertState), |
| 0.0f); |
| } |
| for (int i = 10; i < 1000; i++) { |
| invertState.setLength(i-9); |
| - final float normD = d.computeNorm("foo", invertState); |
| + final float normD = d.computeNorm(invertState); |
| invertState.setLength(i); |
| - final float normS = s.computeNorm("foo", invertState); |
| + final float normS = sp.get("foo").computeNorm(invertState); |
| assertEquals("f: 3,10: 10<x : i="+i, |
| normD, |
| normS, |
| @@ -99,21 +120,21 @@
|
| invertState.setLength(i); |
| assertEquals("f: 8,13: spot i="+i, |
| 1.0f, |
| - s.computeNorm("bar", invertState), |
| + sp.get("bar").computeNorm(invertState), |
| 0.0f); |
| } |
| for (int i = 6; i <=9; i++) { |
| invertState.setLength(i); |
| assertEquals("f: 6,9: spot i="+i, |
| 1.0f, |
| - s.computeNorm("yak", invertState), |
| + sp.get("yak").computeNorm(invertState), |
| 0.0f); |
| } |
| for (int i = 13; i < 1000; i++) { |
| invertState.setLength(i-12); |
| - final float normD = d.computeNorm("foo", invertState); |
| + final float normD = d.computeNorm(invertState); |
| invertState.setLength(i); |
| - final float normS = s.computeNorm("bar", invertState); |
| + final float normS = sp.get("bar").computeNorm(invertState); |
| assertEquals("f: 8,13: 13<x : i="+i, |
| normD, |
| normS, |
| @@ -121,9 +142,9 @@
|
| } |
| for (int i = 9; i < 1000; i++) { |
| invertState.setLength(i-8); |
| - final float normD = d.computeNorm("foo", invertState); |
| + final float normD = d.computeNorm(invertState); |
| invertState.setLength(i); |
| - final float normS = s.computeNorm("yak", invertState); |
| + final float normS = sp.get("yak").computeNorm(invertState); |
| assertEquals("f: 6,9: 9<x : i="+i, |
| normD, |
| normS, |
| @@ -133,13 +154,10 @@
|
| |
| // steepness |
| |
| - ss.setLengthNormFactors("a",5,8,0.5f, false); |
| - ss.setLengthNormFactors("b",5,8,0.1f, false); |
| - |
| for (int i = 9; i < 1000; i++) { |
| invertState.setLength(i); |
| - final float normSS = ss.computeNorm("a", invertState); |
| - final float normS = s.computeNorm("b", invertState); |
| + final float normSS = sp.get("a").computeNorm(invertState); |
| + final float normS = sp.get("b").computeNorm(invertState); |
| assertTrue("s: i="+i+" : a="+normSS+ |
| " < b="+normS, |
| normSS < normS); |
| Index: lucene/contrib/misc/src/test/org/apache/lucene/misc/TestLengthNormModifier.java
|
| ===================================================================
|
| --- lucene/contrib/misc/src/test/org/apache/lucene/misc/TestLengthNormModifier.java (revision 1068958)
|
| +++ lucene/contrib/misc/src/test/org/apache/lucene/misc/TestLengthNormModifier.java (working copy)
|
| @@ -49,7 +49,7 @@
|
| /** inverts the normal notion of lengthNorm */ |
| public static SimilarityProvider s = new DefaultSimilarity() { |
| @Override |
| - public float computeNorm(String fieldName, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| return state.getBoost() * (discountOverlaps ? state.getLength() - state.getNumOverlap() : state.getLength()); |
| } |
| }; |
| @@ -165,7 +165,7 @@
|
| // override the norms to be inverted |
| SimilarityProvider s = new DefaultSimilarity() { |
| @Override |
| - public float computeNorm(String fieldName, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| return state.getBoost() * (discountOverlaps ? state.getLength() - state.getNumOverlap() : state.getLength()); |
| } |
| }; |
| Index: lucene/contrib/misc/src/java/org/apache/lucene/index/FieldNormModifier.java
|
| ===================================================================
|
| --- lucene/contrib/misc/src/java/org/apache/lucene/index/FieldNormModifier.java (revision 1068958)
|
| +++ lucene/contrib/misc/src/java/org/apache/lucene/index/FieldNormModifier.java (working copy)
|
| @@ -149,7 +149,7 @@
|
| for (int d = 0; d < termCounts.length; d++) { |
| if (delDocs == null || !delDocs.get(d)) { |
| invertState.setLength(termCounts[d]); |
| - subReader.setNorm(d, fieldName, fieldSim.encodeNormValue(fieldSim.computeNorm(fieldName, invertState))); |
| + subReader.setNorm(d, fieldName, fieldSim.encodeNormValue(fieldSim.computeNorm(invertState))); |
| } |
| } |
| } |
| Index: lucene/contrib/misc/src/java/org/apache/lucene/misc/SweetSpotSimilarity.java
|
| ===================================================================
|
| --- lucene/contrib/misc/src/java/org/apache/lucene/misc/SweetSpotSimilarity.java (revision 1068958)
|
| +++ lucene/contrib/misc/src/java/org/apache/lucene/misc/SweetSpotSimilarity.java (working copy)
|
| @@ -20,9 +20,6 @@
|
| import org.apache.lucene.search.DefaultSimilarity; |
| import org.apache.lucene.index.FieldInvertState; |
| |
| -import java.util.Map; |
| -import java.util.HashMap; |
| - |
| /** |
| * A similarity with a lengthNorm that provides for a "plateau" of |
| * equally good lengths, and tf helper functions. |
| @@ -50,11 +47,6 @@
|
| private int ln_max = 1; |
| private float ln_steep = 0.5f; |
| |
| - private Map<String,Number> ln_maxs = new HashMap<String,Number>(7); |
| - private Map<String,Number> ln_mins = new HashMap<String,Number>(7); |
| - private Map<String,Float> ln_steeps = new HashMap<String,Float>(7); |
| - private Map<String,Boolean> ln_overlaps = new HashMap<String,Boolean>(7); |
| - |
| private float tf_base = 0.0f; |
| private float tf_min = 0.0f; |
| |
| @@ -98,55 +90,31 @@
|
| * Sets the default function variables used by lengthNorm when no field |
| * specific variables have been set. |
| * |
| - * @see #lengthNorm |
| + * @see #computeLengthNorm |
| */ |
| - public void setLengthNormFactors(int min, int max, float steepness) { |
| + public void setLengthNormFactors(int min, int max, float steepness, boolean discountOverlaps) { |
| this.ln_min = min; |
| this.ln_max = max; |
| this.ln_steep = steepness; |
| + this.discountOverlaps = discountOverlaps; |
| } |
| - |
| - /** |
| - * Sets the function variables used by lengthNorm for a specific named field. |
| - * |
| - * @param field field name |
| - * @param min minimum value |
| - * @param max maximum value |
| - * @param steepness steepness of the curve |
| - * @param discountOverlaps if true, <code>numOverlapTokens</code> will be |
| - * subtracted from <code>numTokens</code>; if false then |
| - * <code>numOverlapTokens</code> will be assumed to be 0 (see |
| - * {@link DefaultSimilarity#computeNorm(String, FieldInvertState)} for details). |
| - * |
| - * @see #lengthNorm |
| - */ |
| - public void setLengthNormFactors(String field, int min, int max, |
| - float steepness, boolean discountOverlaps) { |
| - ln_mins.put(field, Integer.valueOf(min)); |
| - ln_maxs.put(field, Integer.valueOf(max)); |
| - ln_steeps.put(field, Float.valueOf(steepness)); |
| - ln_overlaps.put(field, new Boolean(discountOverlaps)); |
| - } |
| |
| /** |
| * Implemented as <code> state.getBoost() * |
| - * lengthNorm(fieldName, numTokens) </code> where |
| + * computeLengthNorm(numTokens) </code> where |
| * numTokens does not count overlap tokens if |
| * discountOverlaps is true by default or true for this |
| * specific field. */ |
| @Override |
| - public float computeNorm(String fieldName, FieldInvertState state) { |
| + public float computeNorm(FieldInvertState state) { |
| final int numTokens; |
| - boolean overlaps = discountOverlaps; |
| - if (ln_overlaps.containsKey(fieldName)) { |
| - overlaps = ln_overlaps.get(fieldName).booleanValue(); |
| - } |
| - if (overlaps) |
| + |
| + if (discountOverlaps) |
| numTokens = state.getLength() - state.getNumOverlap(); |
| else |
| numTokens = state.getLength(); |
| |
| - return state.getBoost() * computeLengthNorm(fieldName, numTokens); |
| + return state.getBoost() * computeLengthNorm(numTokens); |
| } |
| |
| /** |
| @@ -167,21 +135,11 @@
|
| * |
| * @see #setLengthNormFactors |
| */ |
| - public float computeLengthNorm(String fieldName, int numTerms) { |
| - int l = ln_min; |
| - int h = ln_max; |
| - float s = ln_steep; |
| + public float computeLengthNorm(int numTerms) { |
| + final int l = ln_min; |
| + final int h = ln_max; |
| + final float s = ln_steep; |
| |
| - if (ln_mins.containsKey(fieldName)) { |
| - l = ln_mins.get(fieldName).intValue(); |
| - } |
| - if (ln_maxs.containsKey(fieldName)) { |
| - h = ln_maxs.get(fieldName).intValue(); |
| - } |
| - if (ln_steeps.containsKey(fieldName)) { |
| - s = ln_steeps.get(fieldName).floatValue(); |
| - } |
| - |
| return (float) |
| (1.0f / |
| Math.sqrt |
| Index: lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
|
| ===================================================================
|
| --- lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (revision 1068958)
|
| +++ lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (working copy)
|
| @@ -1190,7 +1190,7 @@
|
| int numOverlapTokens = info != null ? info.numOverlapTokens : 0; |
| float boost = info != null ? info.getBoost() : 1.0f; |
| FieldInvertState invertState = new FieldInvertState(0, numTokens, numOverlapTokens, 0, boost); |
| - float n = fieldSim.computeNorm(fieldName, invertState); |
| + float n = fieldSim.computeNorm(invertState); |
| byte norm = fieldSim.encodeNormValue(n); |
| norms = new byte[] {norm}; |
| |