lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Enrique Lamas" <enrique.la...@corp.ya.com>
Subject lengthNorm method of Similarity not beeing called
Date Mon, 07 Aug 2006 11:05:33 GMT
Hi,
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:
http://www.mail-archive.com/java-user@lucene.apache.org/msg03304.html
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 = multi.search(query, new Sort(new SortField[]{
  SortField.FIELD_SCORE,
  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, hits.id(i));
 System.err.println("explanation: " + explanation.toString());
}
[...]

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


Thanks

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