You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Craig Stadler <cs...@hotmail.com> on 2011/11/04 18:39:01 UTC

Term frequency question

I am using this reference link: 
http://www.mail-archive.com/solr-user@lucene.apache.org/msg26389.html

However the article is a bit old and when I try to compile the class (using 
newest solr 3.4 / java version "1.7.0_01" / Java(TM) SE Runtime Environment 
(build 1.7.0_01-b08) / Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, 
mixed mode)

 I get :
-
 javac -classpath /var/lib/lucene_master/lib/lucene-core-3.4.0.jar 
./NoLengthNormAndTfSimilarity.java

./NoLengthNormAndTfSimilarity.java:7: error: lengthNorm(String,int) in 
NoLengthNormAndTfSimilarity cannot override lengthNorm(String,int) in 
Similarity
  public float lengthNorm(String fieldName, int numTerms) {
               ^
  overridden method is final
1 error
-
What am I doing wrong, is there a better way or newer way to do this?

The bottom line is i want the number of words to NOT factor in score, and I 
DO want to use related functions. I tried omitTermFreqAndPositions="true" 
and it did not allow me to use for example "spiderman doc"~100. Loss of all 
functionality

-Craig

--- actual code ---
package mypackagexyz...

import org.apache.lucene.search.DefaultSimilarity;

public class NoLengthNormAndTfSimilarity extends DefaultSimilarity {

 public float lengthNorm(String fieldName, int numTerms) {
 return numTerms > 0 ? 1.0f : 0.0f;
 }

 public float tf(float freq) {
 return freq > 0 ? 1.0f : 0.0f;
 }
 }
---


Re: Term frequency question

Posted by Chris Hostetter <ho...@fucit.org>.
: ./NoLengthNormAndTfSimilarity.java:7: error: lengthNorm(String,int) in
: NoLengthNormAndTfSimilarity cannot override lengthNorm(String,int) in
: Similarity
:  public float lengthNorm(String fieldName, int numTerms) {
:               ^
:  overridden method is final
: 1 error
: -
: What am I doing wrong, is there a better way or newer way to do this?

did you look at the javadocs for the method?

https://lucene.apache.org/java/3_4_0/api/core/org/apache/lucene/search/Similarity.html#lengthNorm%28java.lang.String,%20int%29

	"Deprecated. Please override computeNorm instead"


-Hoss