summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-01-25 15:14:54 +0100
committerJon Bratseth <bratseth@oath.com>2018-01-25 15:14:54 +0100
commit1ee253837a1955cea2e789e49d4f661a5b764f54 (patch)
treee02205f3b140c91c707c6756c3b288cab95b5164
parenta73feb8828a357ea79990f944bb13eb54748ec69 (diff)
Let profile.type override profile.inherited.type in listTypes
-rw-r--r--container-search/src/main/java/com/yahoo/search/Query.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/AllTypesQueryProfileVisitor.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java7
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/types/test/MandatoryTestCase.java56
4 files changed, 64 insertions, 3 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/Query.java b/container-search/src/main/java/com/yahoo/search/Query.java
index b2349ed6dfc..20f87afacc1 100644
--- a/container-search/src/main/java/com/yahoo/search/Query.java
+++ b/container-search/src/main/java/com/yahoo/search/Query.java
@@ -464,7 +464,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
QueryProfileProperties queryProfileProperties = properties().getInstance(QueryProfileProperties.class);
if (queryProfileProperties == null) return null; // Valid
StringBuilder missingName = new StringBuilder();
- if (! queryProfileProperties.isComplete(missingName, httpRequest.propertyMap()))
+ if ( ! queryProfileProperties.isComplete(missingName, httpRequest.propertyMap()))
return "Incomplete query: Parameter '" + missingName + "' is mandatory in " +
queryProfileProperties.getQueryProfile() + " but is not set";
else
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/AllTypesQueryProfileVisitor.java b/container-search/src/main/java/com/yahoo/search/query/profile/AllTypesQueryProfileVisitor.java
index c194ec235bd..4b83b716635 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/AllTypesQueryProfileVisitor.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/AllTypesQueryProfileVisitor.java
@@ -32,7 +32,7 @@ final class AllTypesQueryProfileVisitor extends PrefixQueryProfileVisitor {
}
private void addReachableTypes(CompoundName name, QueryProfileType type) {
- types.put(name, type);
+ types.putIfAbsent(name, type); // Types visited earlier has precedence: profile.type overrides profile.inherited.type
for (FieldDescription fieldDescription : type.fields().values()) {
if ( ! (fieldDescription.getType() instanceof QueryProfileFieldType)) continue;
QueryProfileFieldType fieldType = (QueryProfileFieldType)fieldDescription.getType();
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java
index ecbdebf1524..04dd3ee9005 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java
@@ -12,7 +12,12 @@ import com.yahoo.search.query.profile.types.FieldDescription;
import com.yahoo.search.query.profile.types.QueryProfileFieldType;
import com.yahoo.search.query.profile.types.QueryProfileType;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/MandatoryTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/MandatoryTestCase.java
index 79c0648614b..7dc6eb3d8aa 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/MandatoryTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/MandatoryTestCase.java
@@ -205,6 +205,62 @@ public class MandatoryTestCase {
assertError(null, new Query(HttpRequest.createTestRequest("?myString=aString&myQueryProfile=otherUser&myQueryProfile.myUserString=userString", Method.GET), cRegistry.getComponent("test")));
}
+ private static class Fixture2 {
+
+ final QueryProfileRegistry registry = new QueryProfileRegistry();
+ final QueryProfileTypeRegistry typeRegistry = new QueryProfileTypeRegistry();
+ final QueryProfileType rootType = new QueryProfileType(new ComponentId("root"));
+ final QueryProfileType mandatoryType = new QueryProfileType(new ComponentId("mandatory-type"));
+
+ public Fixture2() {
+ typeRegistry.register(rootType);
+ typeRegistry.register(mandatoryType);
+
+ mandatoryType.inherited().add(rootType);
+ mandatoryType.addField(new FieldDescription("foobar", FieldType.fromString("string", typeRegistry), true));
+ }
+
+ }
+
+ @Test
+ public void testMandatoryInParentType() {
+ Fixture2 fixture = new Fixture2();
+
+ QueryProfile defaultProfile = new QueryProfile("default");
+ defaultProfile.setType(fixture.rootType);
+
+ QueryProfile mandatoryProfile = new QueryProfile("mandatory");
+ mandatoryProfile.setType(fixture.rootType);
+ mandatoryProfile.setType(fixture.mandatoryType);
+
+ fixture.registry.register(defaultProfile);
+ fixture.registry.register(mandatoryProfile);
+ CompiledQueryProfileRegistry cRegistry = fixture.registry.compile();
+
+ assertError("Incomplete query: Parameter 'foobar' is mandatory in query profile 'mandatory' of type 'mandatory-type' but is not set",
+ new Query(QueryTestCase.httpEncode("?queryProfile=mandatory"), cRegistry.getComponent("mandatory")));
+ }
+
+ @Test
+ public void testMandatoryInParentTypeWithInheritance() {
+ Fixture2 fixture = new Fixture2();
+
+ QueryProfile defaultProfile = new QueryProfile("default");
+ defaultProfile.setType(fixture.rootType);
+
+ QueryProfile mandatoryProfile = new QueryProfile("mandatory");
+ mandatoryProfile.setType(fixture.rootType);
+ mandatoryProfile.addInherited(defaultProfile); // The single difference from the test above
+ mandatoryProfile.setType(fixture.mandatoryType);
+
+ fixture.registry.register(defaultProfile);
+ fixture.registry.register(mandatoryProfile);
+ CompiledQueryProfileRegistry cRegistry = fixture.registry.compile();
+
+ assertError("Incomplete query: Parameter 'foobar' is mandatory in query profile 'mandatory' of type 'mandatory-type' but is not set",
+ new Query(QueryTestCase.httpEncode("?queryProfile=mandatory"), cRegistry.getComponent("mandatory")));
+ }
+
private void assertError(String message,Query query) {
assertEquals(message, query.validate());
}