Index: contrib/misc/src/java/org/apache/lucene/misc/LnbLtcSimilarity.java
===================================================================
--- contrib/misc/src/java/org/apache/lucene/misc/LnbLtcSimilarity.java	(revision 0)
+++ contrib/misc/src/java/org/apache/lucene/misc/LnbLtcSimilarity.java	(revision 0)
@@ -0,0 +1,121 @@
+package org.apache.lucene.misc;
+
+/**
+ * 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.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.search.DefaultSimilarity;
+import org.apache.lucene.search.Similarity; // @javadoc link
+
+/**
+ * A {@link Similarity} with logarithmic term frequency weighting and pivoted
+ * length normalization.
+ * <p>
+ * Implements a scheme similar to the lnb.ltc scheme presented in: 
+ * <blockquote>
+ * <i>Length Normalization in Degraded Text Collections</i>. Amit Singhal,
+ * Gerard Salton, Chris Buckley. Fifth Annual Symposium on Document Analysis and
+ * Information Retrieval, 149-162, 1996. 
+ * </blockquote> 
+ * also described in:
+ * <blockquote> <i>Term Weighting Revisited</i>, Amitabh Kumar Singhal, PhD
+ * Thesis, 1997. 
+ * </blockquote>
+ * and
+ * <blockquote> <i>Pivoted Document Length Normalization</i>, Amit Singhal, 
+ * Chris Buckley, Mandar Mitra. ACM SIGIR'96, 21-29, 1996.
+ * </blockquote>
+ * <p>
+ * This is the formula for document term weights in degraded text collections,
+ * except with minor modifications:
+ * <ul>
+ * <li>Instead of using the average length in raw bytes as a pivot, the average
+ * total number of terms is used (similar to the BM25 length normalization).
+ * <li>Instead of using a default recommended slope of 0.3, a default of 0.25 
+ * is used.
+ * </ul>
+ * <p>
+ * WARNING: In order for this Similarity to be helpful, you must supply the
+ * pivot values (average number of terms per field).
+ */
+
+public class LnbLtcSimilarity extends DefaultSimilarity {
+  public static final float RECOMMENDED_DEFAULT_SLOPE = 0.25f;
+  private final float defaultSlope;
+  private final float defaultPivot;
+  
+  private Map<String,Float> slopes = new HashMap<String,Float>(7);  
+  private Map<String,Float> pivots = new HashMap<String,Float>(7);
+  
+  /**
+   * Create a new LnbLtcSimilarity with default pivot value (avgNumberOfTerms)
+   * to be used when field-specific values have not been provided. The default
+   * slope will be set to {@link #RECOMMENDED_DEFAULT_SLOPE}.
+   * 
+   * @param avgNumberOfTerms default pivot (avgNumberOfTerms for the field)
+   */
+  public LnbLtcSimilarity(float avgNumberOfTerms) {
+    this(avgNumberOfTerms, RECOMMENDED_DEFAULT_SLOPE);
+  }
+  
+  /**
+   * Create a new LnbLtcSimilarity with default pivot (avgNumberOfTerms) and
+   * slope values to be used when field-specific values have not been provided.
+   * 
+   * @param avgNumberOfTerms default pivot (avgNumberOfTerms for the field)
+   * @param defaultSlope default slope
+   * @see #RECOMMENDED_DEFAULT_SLOPE
+   */
+  public LnbLtcSimilarity(float avgNumberOfTerms, float defaultSlope) {
+    this.defaultPivot = avgNumberOfTerms;
+    this.defaultSlope = defaultSlope;
+  }
+  
+  /**
+   * Set the length normalization factors for a field.
+   * 
+   * @param field field name
+   * @param avgNumberOfTerms pivot (avgNumberOfTerms for the field)
+   * @param slope slope value
+   * @see #RECOMMENDED_DEFAULT_SLOPE
+   */
+  public void setLengthNormFactors(String field, float avgNumberOfTerms,
+      float slope) {
+    pivots.put(field, avgNumberOfTerms);
+    slopes.put(field, slope);
+  }
+  
+  @Override
+  public float tf(float freq) {
+    return 1 + (float) Math.log(freq);
+  }
+  
+  @Override
+  public float lengthNorm(String fieldName, int numTerms) {
+    float slope = defaultSlope;
+    if (slopes.containsKey(fieldName))
+      slope = slopes.get(fieldName);
+    
+    float pivot = defaultPivot;
+    if (pivots.containsKey(fieldName))
+      pivot = slopes.get(fieldName);
+    
+    return (float) (1 / ((1 - slope) * pivot + slope * numTerms));
+  }
+}

Property changes on: contrib\misc\src\java\org\apache\lucene\misc\LnbLtcSimilarity.java
___________________________________________________________________
Added: svn:eol-style
   + native

