diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-10-14 22:21:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-14 22:21:27 +0200 |
commit | 777a6a5fca253a104c97f47ccdad1f231f1e951b (patch) | |
tree | 2ddf8ceb4b46c15683ad5eedb3c78d35dfac188a | |
parent | 570222ec5aa05a3c56d8876cf910e9aa7da42acf (diff) |
Revert "Revert "Simplify and correct isFilled""
7 files changed, 52 insertions, 59 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/result/HitGroup.java b/container-search/src/main/java/com/yahoo/search/result/HitGroup.java index cc0aea74d70..c008b133595 100644 --- a/container-search/src/main/java/com/yahoo/search/result/HitGroup.java +++ b/container-search/src/main/java/com/yahoo/search/result/HitGroup.java @@ -844,62 +844,18 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< return fillableHits().iterator().hasNext(); } + /** Returns the set of summaries for which all concrete hits recursively below this is filled. */ @Override public Set<String> getFilled() { - Iterator<Hit> hitIterator = hits.iterator(); - Set<String> firstSummaryNames = getSummaryNamesNextFilledHit(hitIterator); - if (firstSummaryNames == null || firstSummaryNames.isEmpty()) - return firstSummaryNames; - - Set<String> intersection = firstSummaryNames; - while (true) { - Set<String> summaryNames = getSummaryNamesNextFilledHit(hitIterator); - if (summaryNames == null) - break; - - if (intersection.size() == 1) - return getFilledSingle(first(intersection), hitIterator); - - - boolean notInSet = false; - if (intersection == firstSummaryNames) { - if (intersection.size() == summaryNames.size()) { - for(String s : summaryNames) { - if ( ! intersection.contains(s)) { - intersection = new HashSet<>(firstSummaryNames); - notInSet = true; - break; - } - } - } - } - if (notInSet) { - intersection.retainAll(summaryNames); - } - - } - - return intersection; - } - - private Set<String> getSummaryNamesNextFilledHit(Iterator<Hit> hitIterator) { - while (hitIterator.hasNext()) { - Set<String> filled = hitIterator.next().getFilled(); - if (filled != null) - return filled; - } - return null; - } - - private Set<String> getFilledSingle(String summaryName, Iterator<Hit> hitIterator) { - while (true) { - Set<String> summaryNames = getSummaryNamesNextFilledHit(hitIterator); - if (summaryNames == null) { - return Collections.singleton(summaryName); - } else if (!summaryNames.contains(summaryName)) { - return Collections.emptySet(); - } + Set<String> filled = null; + for (Hit hit : hits) { + if (hit.getFilled() == null) continue; + if (filled == null) + filled = new HashSet<>(hit.getFilled()); + else + filled.retainAll(hit.getFilled()); } + return filled; } private Iterable<Hit> fillableHits() { diff --git a/container-search/src/test/java/com/yahoo/search/result/test/FillingTestCase.java b/container-search/src/test/java/com/yahoo/search/result/test/FillingTestCase.java index 01383ba29f2..8a068b7cb3b 100644 --- a/container-search/src/test/java/com/yahoo/search/result/test/FillingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/result/test/FillingTestCase.java @@ -5,6 +5,9 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; import org.junit.Test; +import java.util.Collections; + +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -50,6 +53,40 @@ public class FillingTestCase { assertTrue(group.isFilled("otherSummary")); } + @Test + public void testPartiallyFilledWith2Hits() { + Hit hit1 = new Hit("id1"); + Hit hit2 = new Hit("id2"); + + hit1.setFilled("summary"); + hit2.setFillable(); + + HitGroup hits = new HitGroup(); + hits.add(hit1); + hits.add(hit2); + + assertEquals(Collections.emptySet(), hits.getFilled()); + } + + @Test + public void testPartiallyFilledDiverse() { + Hit hit1 = new Hit("id1"); + Hit hit2 = new Hit("id2"); + Hit hit3 = new Hit("id3"); + + hit1.setFilled("summary1"); + hit1.setFilled("summary2"); + hit2.setFilled("summary1"); + hit3.setFilled("summary1"); + + HitGroup hits = new HitGroup(); + hits.add(hit1); + hits.add(hit2); + hits.add(hit3); + + assertEquals(Collections.singleton("summary1"), hits.getFilled()); + } + private Hit createNonFilled(String id) { Hit hit=new Hit(id); hit.setFillable(); diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java index 4f5b30444a9..06edd222be2 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java @@ -30,7 +30,7 @@ public final class FeedParams { * Enumeration of data formats that are acceptable by the OutputStream * returned by {@link com.yahoo.vespa.http.client.Session#stream(CharSequence)}. */ - public static enum DataFormat { + public enum DataFormat { /** UTF-8-encoded XML. Preamble is not necessary. */ XML_UTF8, JSON_UTF8 diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java index 9a8640d09e2..eb3e8ec982b 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java @@ -35,6 +35,7 @@ public final class SessionParams { * settings, use {@link #setConnectionParams(ConnectionParams)}. */ public static final class Builder { + private final List<Cluster> clusters = new LinkedList<>(); private FeedParams feedParams = new FeedParams.Builder().build(); private ConnectionParams connectionParams = new ConnectionParams.Builder().build(); diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java index c2e94e14486..e9852de215a 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java @@ -160,8 +160,8 @@ class ApacheGatewayConnection implements GatewayConnection { } private ByteBuffer[] getDataWithStartAndEndOfFeed(List<Document> docs, int version) { - List<ByteBuffer> data = new ArrayList<ByteBuffer>(); - if (version == 2 || version == 3) { + List<ByteBuffer> data = new ArrayList<>(); + if (version == 2 || version == 3) { // TODO: Vespa 7: Remove support for version 2 for (Document doc : docs) { int operationSize = doc.size() + startOfFeed.length + endOfFeed.length; StringBuilder envelope = new StringBuilder(); diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java index 61ff84cfdaa..52d999f1a52 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java @@ -43,7 +43,6 @@ import java.util.zip.GZIPInputStream; * Accept feeds from outside of the Vespa cluster. * * @author Steinar Knutsen - * @since 5.1 */ public class FeedHandler extends LoggingRequestHandler { @@ -131,7 +130,7 @@ public class FeedHandler extends LoggingRequestHandler { int version; if (washedClientVersions.contains("3")) { version = 3; - } else if (washedClientVersions.contains("2")) { + } else if (washedClientVersions.contains("2")) { // TODO: Vespa 7: Remove support for Version 2 version = 2; } else { return new Tuple2<>(new ErrorHttpResponse( diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeederSettings.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeederSettings.java index 060cd6ca0a6..874509dd2f8 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeederSettings.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeederSettings.java @@ -9,7 +9,7 @@ import com.yahoo.vespa.http.client.core.Headers; /** * Wrapper for the feed feederSettings read from HTTP request. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class FeederSettings { |