lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Che, Dong" <ched...@yahoo.com>
Subject Customize sorting search results via sorting source before indexing
Date Sat, 10 Aug 2002 19:09:37 GMT
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>


Mime
View raw message