Mailing List Archive

Customize sorting search results via sorting source before indexing
If data source is sorted by some field before indexing
and use docID instead of search score for sorting:
we'll get search result sorted by some field


modify IndexSearcher's HitCollector:
...about line 112
scorer.score(new HitCollector() {
private float minScore = 0.0f;
public final void collect(int doc, float score) {
if (score > 0.0f && // ignore zeroed buckets
(bits==null || bits.get(doc))) { // skip docs
not in bits
totalHits[0]++;
if (score >= minScore) {
/* lucene calculate score for sorting docs
* hq.put(new ScoreDoc(doc, score)); //
update hit queue
* so if we use docID or 1/docID instead of
score for sorting
* we'll get search result sort by docID or by
docID desc
* if data was sorted by some field before
indexing
* we'll get search result sort by some
field...
*/
hq.put(new ScoreDoc(doc, (float) doc)); //
<==use doc instead of score for sorting
if (hq.size() > nDocs) { // if hit queue
overfull
hq.pop(); // remove lowest in hit queue
minScore = ((ScoreDoc)hq.top()).score; // reset
minScore
}
}
}
}
}, reader.maxDoc());

_________________________________________________________
Do You Yahoo!?
ÐÂÏʵ½µ×,ÓéÀÖµ½¼Ò - ÑÅ»¢ÍƳöÃâ·ÑÓéÀÖµç×ÓÖܱ¨!
http://cn.ent.yahoo.com/newsletter/index.html

--
To unsubscribe, e-mail: <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>