diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-10-14 19:20:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-14 19:20:56 +0200 |
commit | 7518ce3820175680c68b4d574a1520028d663092 (patch) | |
tree | e5ff47b26436a22ab02a548f79ff29b0d02c800f | |
parent | 46e014afbe93b74b977ea1c0055df3ae063cadb3 (diff) |
Revert "Simplify and correct isFilled"
7 files changed, 59 insertions, 52 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 c008b133595..cc0aea74d70 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,18 +844,62 @@ 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() { - 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()); + 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(); + } } - 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 8a068b7cb3b..01383ba29f2 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,9 +5,6 @@ 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; @@ -53,40 +50,6 @@ 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 06edd222be2..4f5b30444a9 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 enum DataFormat { + public static 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 eb3e8ec982b..9a8640d09e2 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,7 +35,6 @@ 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 e9852de215a..c2e94e14486 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<>(); - if (version == 2 || version == 3) { // TODO: Vespa 7: Remove support for version 2 + List<ByteBuffer> data = new ArrayList<ByteBuffer>(); + if (version == 2 || version == 3) { 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 52d999f1a52..61ff84cfdaa 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,6 +43,7 @@ import java.util.zip.GZIPInputStream; * Accept feeds from outside of the Vespa cluster. * * @author Steinar Knutsen + * @since 5.1 */ public class FeedHandler extends LoggingRequestHandler { @@ -130,7 +131,7 @@ public class FeedHandler extends LoggingRequestHandler { int version; if (washedClientVersions.contains("3")) { version = 3; - } else if (washedClientVersions.contains("2")) { // TODO: Vespa 7: Remove support for Version 2 + } else if (washedClientVersions.contains("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 874509dd2f8..060cd6ca0a6 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 Steinar Knutsen + * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> */ public class FeederSettings { |