01 package gate.creole.annic.apache.lucene.search;
02
03 /**
04 * Copyright 2004 The Apache Software Foundation
05 *
06 * Licensed under the Apache License, Version 2.0 (the "License");
07 * you may not use this file except in compliance with the License.
08 * You may obtain a copy of the License at
09 *
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 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 }
|