KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > search > DefaultSimilarity


1 package org.apache.lucene.search;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 /** Expert: Default scoring implementation. */
20 public class DefaultSimilarity extends Similarity {
21   /** Implemented as <code>1/sqrt(numTerms)</code>. */
22   public float lengthNorm(String JavaDoc fieldName, int numTerms) {
23     return (float)(1.0 / Math.sqrt(numTerms));
24   }
25   
26   /** Implemented as <code>1/sqrt(sumOfSquaredWeights)</code>. */
27   public float queryNorm(float sumOfSquaredWeights) {
28     return (float)(1.0 / Math.sqrt(sumOfSquaredWeights));
29   }
30
31   /** Implemented as <code>sqrt(freq)</code>. */
32   public float tf(float freq) {
33     return (float)Math.sqrt(freq);
34   }
35     
36   /** Implemented as <code>1 / (distance + 1)</code>. */
37   public float sloppyFreq(int distance) {
38     return 1.0f / (distance + 1);
39   }
40     
41   /** Implemented as <code>log(numDocs/(docFreq+1)) + 1</code>. */
42   public float idf(int docFreq, int numDocs) {
43     return (float)(Math.log(numDocs/(double)(docFreq+1)) + 1.0);
44   }
45     
46   /** Implemented as <code>overlap / maxOverlap</code>. */
47   public float coord(int overlap, int maxOverlap) {
48     return overlap / (float)maxOverlap;
49   }
50 }
51
Popular Tags