Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Lucene: Java-User

lengthNorm method of Similarity not beeing called

 

 

Lucene java-user RSS feed   Index | Next | Previous | View Threaded


enrique.lamas at corp

Aug 7, 2006, 4:05 AM

Post #1 of 2 (356 views)
Permalink
lengthNorm method of Similarity not beeing called

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 [at] lucene/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


lucene at mikemccandless

Aug 7, 2006, 5:03 AM

Post #2 of 2 (334 views)
Permalink
Re: lengthNorm method of Similarity not beeing called [In reply to]

> 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.

The lengthNorm() method, I believe, is only called during indexing. Its
purpose is to translate the number of terms that occurred in a given
field, into a score factor that is used at query time.

Can you verify that you called IndexWriter.setSimilarity() (as above)
before adding documents to the index? And then see if your lengthNorm()
is then being called?

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene

Lucene java-user RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.