You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "gaobinlong (via GitHub)" <gi...@apache.org> on 2026/05/18 07:18:00 UTC
[PR] Fix LargeNumHitsTopDocsCollector not handling requested hit count correctly [lucene]
gaobinlong opened a new pull request, #16078:
URL: https://github.com/apache/lucene/pull/16078
### Description
This is a follow-up PR for https://github.com/apache/lucene/pull/15660, in LargeNumHitsTopDocsCollector, we should
1) reject 0 and negative values for requestedHitCount in the constructor, that makes more sense
2) in topDocs(int howMany) method, we should return empty TopDocs directly in case of howMany ==0, and return all hits if howMany> totalHitsCount, this is consistent with TopDocsCollector.topDocs(int start, int howMany)https://github.com/apache/lucene/blob/9f33b54a13a05b2931fc798381a225b10229e704/lucene/core/src/java/org/apache/lucene/search/TopDocsCollector.java#L131
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Fix LargeNumHitsTopDocsCollector not handling requested hit count correctly [lucene]
Posted by "javanna (via GitHub)" <gi...@apache.org>.
javanna commented on code in PR #16078:
URL: https://github.com/apache/lucene/pull/16078#discussion_r3258940631
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/LargeNumHitsTopDocsCollector.java:
##########
@@ -111,10 +114,14 @@ public void collect(int doc) throws IOException {
/** Returns the top docs that were collected by this collector. */
public TopDocs topDocs(int howMany) {
-
- if (howMany <= 0 || howMany > totalHits) {
- throw new IllegalArgumentException("Incorrect number of hits requested");
+ if (howMany < 0) {
+ throw new IllegalArgumentException(
+ "Number of hits requested must not be negative but value was " + howMany);
+ }
+ if (howMany == 0) {
Review Comment:
I now wonder, if we don't accept 0 above, why should we accept it here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Fix LargeNumHitsTopDocsCollector not handling requested hit count correctly [lucene]
Posted by "javanna (via GitHub)" <gi...@apache.org>.
javanna merged PR #16078:
URL: https://github.com/apache/lucene/pull/16078
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Fix LargeNumHitsTopDocsCollector not handling requested hit count correctly [lucene]
Posted by "javanna (via GitHub)" <gi...@apache.org>.
javanna commented on code in PR #16078:
URL: https://github.com/apache/lucene/pull/16078#discussion_r3265269114
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/LargeNumHitsTopDocsCollector.java:
##########
@@ -111,10 +114,14 @@ public void collect(int doc) throws IOException {
/** Returns the top docs that were collected by this collector. */
public TopDocs topDocs(int howMany) {
-
- if (howMany <= 0 || howMany > totalHits) {
- throw new IllegalArgumentException("Incorrect number of hits requested");
+ if (howMany < 0) {
+ throw new IllegalArgumentException(
+ "Number of hits requested must not be negative but value was " + howMany);
+ }
+ if (howMany == 0) {
Review Comment:
cool, thanks for clarifying
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Fix LargeNumHitsTopDocsCollector not handling requested hit count correctly [lucene]
Posted by "gaobinlong (via GitHub)" <gi...@apache.org>.
gaobinlong commented on code in PR #16078:
URL: https://github.com/apache/lucene/pull/16078#discussion_r3264102786
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/LargeNumHitsTopDocsCollector.java:
##########
@@ -111,10 +114,14 @@ public void collect(int doc) throws IOException {
/** Returns the top docs that were collected by this collector. */
public TopDocs topDocs(int howMany) {
-
- if (howMany <= 0 || howMany > totalHits) {
- throw new IllegalArgumentException("Incorrect number of hits requested");
+ if (howMany < 0) {
+ throw new IllegalArgumentException(
+ "Number of hits requested must not be negative but value was " + howMany);
+ }
+ if (howMany == 0) {
Review Comment:
0 comes from the public topDocs(), if totalHits is 0, then howMany equals to 0 here. https://github.com/apache/lucene/blob/1d6c321274c590a67189b7b56e0c4e94a293ac15/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/LargeNumHitsTopDocsCollector.java#L165
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org