龙思

提供站内搜索服务

原创 org.apache.lucene.search.Hits.java搜索索引收藏

 
  1.   /**
  2.    * Tries to add new documents to hitDocs.
  3.    * Ensures that the hit numbered <code>min</code> has been retrieved.
  4.    */
  5.   private final void getMoreDocs(int min) throws IOException {
  6.     if (hitDocs.size() > min) {
  7.       min = hitDocs.size();
  8.     }
  9.     int n = min * 2// double # retrieved
  10.     TopDocs topDocs = (sort == null) ? searcher.search(weight, filter, n) : 
  11. searcher.search(weight, filter, n, sort);
  12.     
  13.     length = topDocs.totalHits;
  14.     ScoreDoc[] scoreDocs = topDocs.scoreDocs;
  15.     float scoreNorm = 1.0f;
  16.     
  17.     if (length > 0 && topDocs.getMaxScore() > 1.0f) {
  18.       scoreNorm = 1.0f / topDocs.getMaxScore();
  19.     }
  20.     int start = hitDocs.size() - nDeletedHits;
  21.     // any new deletions?
  22.     int nDels2 = countDeletions(searcher);
  23.     debugCheckedForDeletions = false;
  24.     if (nDeletions < 0 || nDels2 > nDeletions) { 
  25.       // either we cannot count deletions, or some "previously valid hits" 
  26. might have been deleted, so find exact start point
  27.       nDeletedHits = 0;
  28.       debugCheckedForDeletions = true;
  29.       int i2 = 0;
  30.       for (int i1=0; i1<hitDocs.size() && i2<scoreDocs.length; i1++) {
  31.         int id1 = ((HitDoc)hitDocs.get(i1)).id;
  32.         int id2 = scoreDocs[i2].doc;
  33.         if (id1 == id2) {
  34.           i2++;
  35.         } else {
  36.           nDeletedHits ++;
  37.         }
  38.       }
  39.       start = i2;
  40.     }
  41.     int end = scoreDocs.length < length ? scoreDocs.length : length;
  42.     length += nDeletedHits;
  43.     for (int i = start; i < end; i++) {
  44.       hitDocs.addElement(new HitDoc(scoreDocs[i].score * scoreNorm,
  45.                                     scoreDocs[i].doc));
  46.     }
  47.     
  48.     nDeletions = nDels2;
  49.   }

发表于 @ 2008年10月28日 20:45:00|评论(loading...)|收藏

新一篇: 算法导论题解(我的答案,欢迎指正) introduction to algorithms  | 旧一篇: lucene 源码分析

Csdn Blog version 3.1a
Copyright © 龙思