use of com.yahoo.search.query.profile.types.QueryProfileType in project vespa by vespa-engine.
the class PatchMatchingTestCase method testPatchMatching.
public void testPatchMatching() {
QueryProfileType type = new QueryProfileType("type");
type.setMatchAsPath(true);
QueryProfile a = new QueryProfile("a");
a.setType(type);
QueryProfile abee = new QueryProfile("a/bee");
abee.setType(type);
abee.addInherited(a);
QueryProfile abeece = new QueryProfile("a/bee/ce");
abeece.setType(type);
abeece.addInherited(abee);
QueryProfileRegistry registry = new QueryProfileRegistry();
registry.register(a);
registry.register(abee);
registry.register(abeece);
registry.freeze();
// No "default" registered
assertNull(registry.findQueryProfile(null));
assertEquals("a", registry.findQueryProfile("a").getId().getName());
assertEquals("a/bee", registry.findQueryProfile("a/bee").getId().getName());
assertEquals("a/bee/ce", registry.findQueryProfile("a/bee/ce").getId().getName());
assertEquals("a/bee/ce", registry.findQueryProfile("a/bee/ce/dee").getId().getName());
assertEquals("a/bee/ce", registry.findQueryProfile("a/bee/ce/dee/eee/").getId().getName());
assertEquals("a/bee", registry.findQueryProfile("a/bee/cede").getId().getName());
assertEquals("a", registry.findQueryProfile("a/foo/bee/cede").getId().getName());
assertNull(registry.findQueryProfile("abee"));
}
use of com.yahoo.search.query.profile.types.QueryProfileType in project vespa by vespa-engine.
the class PatchMatchingTestCase method testNoPatchMatching.
public void testNoPatchMatching() {
QueryProfileType type = new QueryProfileType("type");
// Default, but set here for clarity
type.setMatchAsPath(false);
QueryProfile a = new QueryProfile("a");
a.setType(type);
QueryProfile abee = new QueryProfile("a/bee");
abee.setType(type);
abee.addInherited(a);
QueryProfile abeece = new QueryProfile("a/bee/ce");
abeece.setType(type);
abeece.addInherited(abee);
QueryProfileRegistry registry = new QueryProfileRegistry();
registry.register(a);
registry.register(abee);
registry.register(abeece);
registry.freeze();
// No "default" registered
assertNull(registry.findQueryProfile(null));
assertEquals("a", registry.findQueryProfile("a").getId().getName());
assertEquals("a/bee", registry.findQueryProfile("a/bee").getId().getName());
assertEquals("a/bee/ce", registry.findQueryProfile("a/bee/ce").getId().getName());
// Different from test above
assertNull(registry.findQueryProfile("a/bee/ce/dee"));
// Different from test above
assertNull(registry.findQueryProfile("a/bee/ce/dee/eee/"));
// Different from test above
assertNull(registry.findQueryProfile("a/bee/cede"));
// Different from test above
assertNull(registry.findQueryProfile("a/foo/bee/cede"));
assertNull(registry.findQueryProfile("abee"));
}
use of com.yahoo.search.query.profile.types.QueryProfileType in project vespa by vespa-engine.
the class TypedProfilesConfigurationTestCase method testIt.
/**
* Asserts that everything is read correctly from this configuration
*/
public void testIt() {
QueryProfileConfigurer configurer = new QueryProfileConfigurer("file:src/test/java/com/yahoo/search/query/profile/config/test/typed-profiles.cfg");
QueryProfileRegistry registry = configurer.getCurrentRegistry();
QueryProfileTypeRegistry types = registry.getTypeRegistry();
// Assert that each type was read correctly
QueryProfileType testType = types.getComponent("testtype");
assertEquals("testtype", testType.getId().getName());
assertFalse(testType.isStrict());
assertFalse(testType.getMatchAsPath());
assertEquals(7, testType.fields().size());
assertEquals("myString", testType.getField("myString").getName());
assertTrue(testType.getField("myString").isMandatory());
assertTrue(testType.getField("myString").isOverridable());
assertFalse(testType.getField("myInteger").isMandatory());
assertFalse(testType.getField("myInteger").isOverridable());
FieldDescription field = testType.getField("myUserQueryProfile");
assertEquals("reference to a query profile of type 'user'", field.getType().toInstanceDescription());
assertTrue(field.getAliases().contains("myqp"));
assertTrue(field.getAliases().contains("user-profile"));
QueryProfileType testTypeStrict = types.getComponent("testtypestrict");
assertTrue(testTypeStrict.isStrict());
assertTrue(testTypeStrict.getMatchAsPath());
assertEquals(7, testTypeStrict.fields().size());
assertEquals("reference to a query profile of type 'userstrict'", testTypeStrict.getField("myUserQueryProfile").getType().toInstanceDescription());
QueryProfileType user = types.getComponent("user");
assertFalse(user.isStrict());
assertFalse(user.getMatchAsPath());
assertEquals(2, user.fields().size());
assertEquals(String.class, user.getField("myUserString").getType().getValueClass());
QueryProfileType userStrict = types.getComponent("userstrict");
assertTrue(userStrict.isStrict());
assertFalse(userStrict.getMatchAsPath());
assertEquals(2, userStrict.fields().size());
}
use of com.yahoo.search.query.profile.types.QueryProfileType in project vespa by vespa-engine.
the class QueryProfileCompiler method compile.
public static CompiledQueryProfile compile(QueryProfile in, CompiledQueryProfileRegistry registry) {
DimensionalMap.Builder<CompoundName, Object> values = new DimensionalMap.Builder<>();
DimensionalMap.Builder<CompoundName, QueryProfileType> types = new DimensionalMap.Builder<>();
DimensionalMap.Builder<CompoundName, Object> references = new DimensionalMap.Builder<>();
DimensionalMap.Builder<CompoundName, Object> unoverridables = new DimensionalMap.Builder<>();
// Resolve values for each existing variant and combine into a single data structure
Set<DimensionBindingForPath> variants = new HashSet<>();
collectVariants(CompoundName.empty, in, DimensionBinding.nullBinding, variants);
// if this contains no variants
variants.add(new DimensionBindingForPath(DimensionBinding.nullBinding, CompoundName.empty));
if (log.isLoggable(Level.FINE))
log.fine("Compiling " + in.toString() + " having " + variants.size() + " variants");
int i = 0;
for (DimensionBindingForPath variant : variants) {
if (log.isLoggable(Level.FINER))
log.finer(" Compiling variant " + i++ + ": " + variant);
for (Map.Entry<String, Object> entry : in.listValues(variant.path(), variant.binding().getContext(), null).entrySet()) values.put(variant.path().append(entry.getKey()), variant.binding(), entry.getValue());
for (Map.Entry<CompoundName, QueryProfileType> entry : in.listTypes(variant.path(), variant.binding().getContext()).entrySet()) types.put(variant.path().append(entry.getKey()), variant.binding(), entry.getValue());
for (CompoundName reference : in.listReferences(variant.path(), variant.binding().getContext())) // Used as a set; value is ignored
references.put(variant.path().append(reference), variant.binding(), Boolean.TRUE);
for (CompoundName name : in.listUnoverridable(variant.path(), variant.binding().getContext())) // Used as a set; value is ignored
unoverridables.put(variant.path().append(name), variant.binding(), Boolean.TRUE);
}
return new CompiledQueryProfile(in.getId(), in.getType(), values.build(), types.build(), references.build(), unoverridables.build(), registry);
}
use of com.yahoo.search.query.profile.types.QueryProfileType in project vespa by vespa-engine.
the class QueryProfileConfigurer method createProfileType.
private static void createProfileType(QueryProfilesConfig.Queryprofiletype config, QueryProfileTypeRegistry registry) {
QueryProfileType type = new QueryProfileType(config.id());
type.setStrict(config.strict());
type.setMatchAsPath(config.matchaspath());
registry.register(type);
}
Aggregations