当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Search Lucene in decreasing order of doc Id

问题描述:

I hope someone can help me.

I have an index with tens of thousands of documents. Each document consists of several fields with texts and a field with an ID (integer). The search provides a list of the IDs.

To save resources, the maximum number of search results is limited to 10000. Usually this works very well. Now a case occurred, in which more than 10000 results would be found. Let's say 15000. Lucene search by default in increasing order of DocIDs, so Lucene delivers the first 10000 IDs.

I would find it better if Lucene provides the last 10000 IDs and thus the newer documents were found. Is there a way to change the Lucene search in decreasing order?

网友答案:

Just create a sort which sorts by document id in inverse order.

Sort sort = new Sort(
   new SortField(
      null,                    // or specify a field
      SortField.Type.DOC, 
      true
   )
);

And then search for top, err, bottom 10K docs:

indexSearcher.search(query, 10000);
分享给朋友:
您可能感兴趣的文章:
随机阅读: