1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.eos.lucene;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.apache.lucene.search.DefaultSimilarity;
21
22
23
24
25
26 public class NormedLengthSimilarity extends DefaultSimilarity {
27
28 private static final long serialVersionUID = 1070479651291502989L;
29
30
31 private static final Log LOG =
32 LogFactory.getLog(NormedLengthSimilarity.class.getName());
33
34 @Override
35 public float lengthNorm(final String fieldName, final int numTerms) {
36 if (! "TODO".equals(fieldName)) {
37 final float retval = super.lengthNorm(fieldName, numTerms);
38 if (LOG.isTraceEnabled()) {
39 LOG.trace("fieldname: "+ fieldName
40 + " - numTerms: "+ numTerms + " - retval: "
41 + retval);
42 }
43 return retval;
44 }
45 if (LOG.isTraceEnabled()) {
46 LOG.trace("fieldname: "+ fieldName
47 + " - numTerms: "+ numTerms + " - retval: 1.0");
48 }
49 return 1.0f;
50 }
51 @Override
52 public float queryNorm(final float sumOfSquaredWeights) {
53 final float retval = super.queryNorm(sumOfSquaredWeights);
54 if (LOG.isTraceEnabled()) {
55 LOG.trace("sumOfSquaredWeights: "
56 + sumOfSquaredWeights + " - retval: " + retval);
57 }
58 return retval;
59 }
60 @Override
61 public float tf(final float freq) {
62 final float retval = super.tf(freq);
63 if (LOG.isTraceEnabled()) {
64 LOG.trace("freq: "+ freq + " - retval: " + retval);
65 }
66 return retval;
67 }
68 @Override
69 public float sloppyFreq(final int distance) {
70 final float retval = super.sloppyFreq(distance);
71 if (LOG.isTraceEnabled()) {
72 LOG.trace("distance: "+ distance + " - retval: " + retval);
73 }
74 return retval;
75 }
76 @Override
77 public float idf(final int docFreq, final int numDocs) {
78 final float retval = super.idf(docFreq, numDocs);
79 if (LOG.isTraceEnabled()) {
80 LOG.trace("docFreq: "+ docFreq
81 + " - docFreq: " + docFreq + " - retval: " + retval);
82 }
83 return retval;
84 }
85 @Override
86 public float coord(final int overlap, final int maxOverlap) {
87 final float retval = super.idf(overlap, maxOverlap);
88 if (LOG.isTraceEnabled()) {
89 LOG.trace("overlap: "+ overlap
90 + " - maxOverlap: " + maxOverlap + " - retval: "
91 + retval);
92 }
93 return retval;
94 }
95 }