From 1285894f5f68d869d2604d84a122209048d3f782 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Sun, 1 Dec 2013 16:44:19 +0100 Subject: [PATCH] Also short circuit within segment when score mode is avg --- .../index/search/child/ChildrenQuery.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java index ae62abb00bf..eb7cedce71c 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java @@ -338,6 +338,11 @@ public class ChildrenQuery extends Query { @Override public int nextDoc() throws IOException { + if (remaining == 0) { + currentDocId = NO_MORE_DOCS; + return NO_MORE_DOCS; + } + while (true) { currentDocId = parentsIterator.nextDoc(); if (currentDocId == DocIdSetIterator.NO_MORE_DOCS) { @@ -356,6 +361,11 @@ public class ChildrenQuery extends Query { @Override public int advance(int target) throws IOException { + if (remaining == 0) { + currentDocId = NO_MORE_DOCS; + return NO_MORE_DOCS; + } + currentDocId = parentsIterator.advance(target); if (currentDocId == DocIdSetIterator.NO_MORE_DOCS) { return currentDocId;