lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Srinivas.N." <>
Subject Question on custom scoring
Date Mon, 13 Aug 2007 23:34:30 GMT

A few questions on custom score queries:

[1] I need to rank matches by some combination of keyword match, popularity
and recency of the doc. I read the docs about CustomScoreQuery and seems to
be a resonable fit. An alternate way of achieving my goals is  to use a
custom sort. What are the trade-offs between these two approaches?

[2] I implemented the CustomScoreQuery using FieldScoreQuery, but the scores
I get from FieldScoreQuery dont match what I stored in the index. Here is
roughly what my code looks like:

/** At indexing time **/
int popularity = ...;
doc.add(new Field("popularity", Integer.toString(popularity),
Field.Store.YES, Field.Index.UN_TOKENIZED));

int creationTime = ...; // say this is the number of hours since a standard
start time
doc.add(new Field("creationTime", Integer.toString(creationTime),
Field.Store.YES, Field.Index.UN_TOKENIZED));

/** At query time **/
FieldScoreQuery fsQuery = new FieldScoreQuery("popularity",
CustomScoreQuery cq = new CustomScoreQuery(baseQuery, fsQuery) {
	 public float customScore(int doc, float subQueryScore, float valSrcScore)
	        System.out.println("base score =  " + subQueryScore + " valSrcScore
= " + valSrcScore);
		 return (subQueryScore + valSrcScore) / 2;

[a] I was expecting the valSrcScore in the print statement to return the
value I stored in the popularity field in the index. Instead, I get a
different value each time based on the query. And I dont know how to
interpret the value that is returned. Am I doing something strange?

[b] The subQueryScore that is returned in the customScore() API doesnt seem
to be normalized. This makes it difficult for me to weight the different
scores properly. Is there an easy way to get the normalized "text index"
score in customScore() API so I can easaily weigh in the other factors
relative to it?

Thanks a lot in advance,

View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message