Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
DefaultSimilarity.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 
20 using FieldInvertState = Lucene.Net.Index.FieldInvertState;
21 
22 namespace Lucene.Net.Search
23 {
24 
26  [Serializable]
28  {
29 
40  public override float ComputeNorm(System.String field, FieldInvertState state)
41  {
42  int numTerms;
43  if (internalDiscountOverlaps)
44  numTerms = state.Length - state.NumOverlap;
45  else
46  numTerms = state.Length;
47  return (state.Boost * LengthNorm(field, numTerms));
48  }
49 
51  public override float LengthNorm(System.String fieldName, int numTerms)
52  {
53  return (float) (1.0 / System.Math.Sqrt(numTerms));
54  }
55 
57  public override float QueryNorm(float sumOfSquaredWeights)
58  {
59  return (float) (1.0 / System.Math.Sqrt(sumOfSquaredWeights));
60  }
61 
63  public override float Tf(float freq)
64  {
65  return (float) System.Math.Sqrt(freq);
66  }
67 
69  public override float SloppyFreq(int distance)
70  {
71  return 1.0f / (distance + 1);
72  }
73 
75  public override float Idf(int docFreq, int numDocs)
76  {
77  return (float) (System.Math.Log(numDocs / (double) (docFreq + 1)) + 1.0);
78  }
79 
81  public override float Coord(int overlap, int maxOverlap)
82  {
83  return overlap / (float) maxOverlap;
84  }
85 
88  // Default false
89  protected internal bool internalDiscountOverlaps;
90 
102  public virtual bool DiscountOverlaps
103  {
104  get { return internalDiscountOverlaps; }
105  set { internalDiscountOverlaps = value; }
106  }
107  }
108 }