lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Enrique Lamas" <>
Subject lengthNorm method of Similarity not beeing called
Date Mon, 07 Aug 2006 11:05:33 GMT
I want to execute a query and sort the results in a special way. Seeing the Explanation info
returned, I've decided to alter the value that at Explanation is given as fieldNorm. Searching
at this maillist, I found this post:
At this post Erik says:

"Sure, you can subclass DefaultSimilarity and override and tweak just
the lengthNorm() method. Be sure to use IndexWriter.setSimilarity()
to get your custom one used."

Well, I traced my own method lengthNorm and realized that this method is not being called.
┬┐Anyone knows what I'm doing wrong?
All other reimplemented Similarity methods are being called, but not lengthNorm.

I'm using Lucene version 1.9.1

These are my pieces of code:

MultiSearcher multi ...
multi.setSimilarity(new MySimilarity());
QueryParser queryParser = new MultiFieldQueryParser(new String[] {"tags", "title"}, ProcessConstants.analyzer);
Query query = queryParser.parse("rocio ortega");
Hits hits =, new Sort(new SortField[]{
  new SortField("formatted-date", SortField.STRING, true)}));
for (int i = 0; i < hits.length(); i++) {
 org.apache.lucene.document.Document docIndex = hits.doc(i);
 Explanation explanation = multi.explain(query,;
 System.err.println("explanation: " + explanation.toString());

public class MySimilarity extends DefaultSimilarity{
 public MySimilarity(){
 public float lengthNorm(String arg0, int arg1) {
  //System.err.println("**** lengthNorm");
  return super.lengthNorm(arg0, arg1);


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message