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.   }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值