01: package org.apache.lucene.search;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: /** Expert: Default scoring implementation. */
21: public class DefaultSimilarity extends Similarity {
22: /** Implemented as <code>1/sqrt(numTerms)</code>. */
23: public float lengthNorm(String fieldName, int numTerms) {
24: return (float) (1.0 / Math.sqrt(numTerms));
25: }
26:
27: /** Implemented as <code>1/sqrt(sumOfSquaredWeights)</code>. */
28: public float queryNorm(float sumOfSquaredWeights) {
29: return (float) (1.0 / Math.sqrt(sumOfSquaredWeights));
30: }
31:
32: /** Implemented as <code>sqrt(freq)</code>. */
33: public float tf(float freq) {
34: return (float) Math.sqrt(freq);
35: }
36:
37: /** Implemented as <code>1 / (distance + 1)</code>. */
38: public float sloppyFreq(int distance) {
39: return 1.0f / (distance + 1);
40: }
41:
42: /** Implemented as <code>log(numDocs/(docFreq+1)) + 1</code>. */
43: public float idf(int docFreq, int numDocs) {
44: return (float) (Math.log(numDocs / (double) (docFreq + 1)) + 1.0);
45: }
46:
47: /** Implemented as <code>overlap / maxOverlap</code>. */
48: public float coord(int overlap, int maxOverlap) {
49: return overlap / (float) maxOverlap;
50: }
51: }
|