KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > indexer > NutchSimilarity


1 /* Copyright (c) 2003 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3
4 package net.nutch.indexer;
5
6 import org.apache.lucene.search.DefaultSimilarity;
7
8 /** Similarity implementatation used by Nutch indexing and search. */
9 public class NutchSimilarity extends DefaultSimilarity {
10   private static final int MIN_CONTENT_LENGTH = 1000;
11
12   /** Normalize field by length. Called at index time. */
13   public float lengthNorm(String JavaDoc fieldName, int numTokens) {
14     if ("url".equals(fieldName)) { // URL: prefer short
15
return 1.0f / numTokens; // use linear normalization
16

17     } else if ("anchor".equals(fieldName)) { // Anchor: prefer more
18
return (float)(1.0/Math.log(Math.E+numTokens)); // use log
19

20     } else if ("content".equals(fieldName)) { // Content: penalize short
21
return super.lengthNorm(fieldName, // treat short as longer
22
Math.max(numTokens, MIN_CONTENT_LENGTH));
23
24     } else { // use default
25
return super.lengthNorm(fieldName, numTokens);
26     }
27   }
28
29   public float coord(int overlap, int maxOverlap) {
30     return 1.0f;
31   }
32
33 }
34
Popular Tags