use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile in project vespa by vespa-engine.
the class XmlReadingTestCase method testQueryProfileVariants2.
@Test
public void testQueryProfileVariants2() {
CompiledQueryProfileRegistry registry = new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/queryprofilevariants2").compile();
CompiledQueryProfile multi = registry.getComponent("multi");
{
Query query = new Query(HttpRequest.createTestRequest("?queryProfile=multi", Method.GET), multi);
query.validate();
assertEquals("best", query.properties().get("model.queryString"));
assertEquals("best", query.getModel().getQueryString());
}
{
Query query = new Query(HttpRequest.createTestRequest("?queryProfile=multi&myindex=default", Method.GET), multi);
query.validate();
assertEquals("best", query.properties().get("model.queryString"));
assertEquals("best", query.getModel().getQueryString());
assertEquals("default", query.getModel().getDefaultIndex());
}
{
Query query = new Query(HttpRequest.createTestRequest("?queryProfile=multi&myindex=default&myquery=love", Method.GET), multi);
query.validate();
assertEquals("love", query.properties().get("model.queryString"));
assertEquals("love", query.getModel().getQueryString());
assertEquals("default", query.getModel().getDefaultIndex());
}
{
Query query = new Query(HttpRequest.createTestRequest("?model=querybest", Method.GET), multi);
query.validate();
assertEquals("best", query.getModel().getQueryString());
assertEquals("title", query.properties().get("model.defaultIndex"));
assertEquals("title", query.getModel().getDefaultIndex());
}
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile in project vespa by vespa-engine.
the class QueryProfileProperties method listProperties.
@Override
public Map<String, Object> listProperties(CompoundName path, Map<String, String> context, com.yahoo.processing.request.Properties substitution) {
path = unalias(path, context);
if (context == null)
context = Collections.emptyMap();
Map<String, Object> properties = profile.listValues(path, context, substitution);
properties.putAll(super.listProperties(path, context, substitution));
if (references != null) {
for (Pair<CompoundName, CompiledQueryProfile> refEntry : references) {
if (!refEntry.getFirst().hasPrefix(path.first(Math.min(refEntry.getFirst().size(), path.size()))))
continue;
CompoundName pathInReference;
CompoundName prefixToReferenceKeys;
if (refEntry.getFirst().size() > path.size()) {
pathInReference = CompoundName.empty;
prefixToReferenceKeys = refEntry.getFirst().rest(path.size());
} else {
pathInReference = path.rest(refEntry.getFirst().size());
prefixToReferenceKeys = CompoundName.empty;
}
for (Map.Entry<String, Object> valueEntry : refEntry.getSecond().listValues(pathInReference, context, substitution).entrySet()) {
properties.put(prefixToReferenceKeys.append(new CompoundName(valueEntry.getKey())).toString(), valueEntry.getValue());
}
}
}
if (values != null) {
for (Map.Entry<CompoundName, Object> entry : values.entrySet()) {
if (entry.getKey().hasPrefix(path))
properties.put(entry.getKey().rest(path.size()).toString(), entry.getValue());
}
}
return properties;
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile in project vespa by vespa-engine.
the class QueryProfileTestCase method testInheritance.
public void testInheritance() {
QueryProfile barn = new QueryProfile("barn");
QueryProfile mor = new QueryProfile("mor");
QueryProfile far = new QueryProfile("far");
QueryProfile mormor = new QueryProfile("mormor");
QueryProfile morfar = new QueryProfile("morfar");
QueryProfile farfar = new QueryProfile("farfar");
barn.addInherited(mor);
barn.addInherited(far);
mor.addInherited(mormor);
mor.addInherited(morfar);
far.addInherited(farfar);
morfar.set("a", "morfar-a", (QueryProfileRegistry) null);
mormor.set("a", "mormor-a", (QueryProfileRegistry) null);
farfar.set("a", "farfar-a", (QueryProfileRegistry) null);
mor.set("a", "mor-a", (QueryProfileRegistry) null);
far.set("a", "far-a", (QueryProfileRegistry) null);
barn.set("a", "barn-a", (QueryProfileRegistry) null);
mormor.set("b", "mormor-b", (QueryProfileRegistry) null);
far.set("b", "far-b", (QueryProfileRegistry) null);
mor.set("c", "mor-c", (QueryProfileRegistry) null);
far.set("c", "far-c", (QueryProfileRegistry) null);
mor.set("d.a", "mor-d.a", (QueryProfileRegistry) null);
barn.set("d.b", "barn-d.b", (QueryProfileRegistry) null);
QueryProfile annetBarn = new QueryProfile("annetBarn");
annetBarn.set("venn", barn, (QueryProfileRegistry) null);
CompiledQueryProfile cbarn = barn.compile(null);
CompiledQueryProfile cannetBarn = annetBarn.compile(null);
assertEquals("barn-a", cbarn.get("a"));
assertEquals("mormor-b", cbarn.get("b"));
assertEquals("mor-c", cbarn.get("c"));
assertEquals("barn-a", cannetBarn.get("venn.a"));
assertEquals("mormor-b", cannetBarn.get("venn.b"));
assertEquals("mor-c", cannetBarn.get("venn.c"));
assertEquals("barn-d.b", cbarn.get("d.b"));
assertEquals("mor-d.a", cbarn.get("d.a"));
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile in project vespa by vespa-engine.
the class QueryProfileTestCase method testListProperties.
public void testListProperties() {
QueryProfile barn = new QueryProfile("barn");
QueryProfile mor = new QueryProfile("mor");
QueryProfile far = new QueryProfile("far");
QueryProfile mormor = new QueryProfile("mormor");
QueryProfile morfar = new QueryProfile("morfar");
QueryProfile farfar = new QueryProfile("farfar");
barn.addInherited(mor);
barn.addInherited(far);
mor.addInherited(mormor);
mor.addInherited(morfar);
far.addInherited(farfar);
morfar.set("a", "morfar-a", (QueryProfileRegistry) null);
morfar.set("model.b", "morfar-model.b", (QueryProfileRegistry) null);
mormor.set("a", "mormor-a", (QueryProfileRegistry) null);
mormor.set("model.b", "mormor-model.b", (QueryProfileRegistry) null);
farfar.set("a", "farfar-a", (QueryProfileRegistry) null);
mor.set("a", "mor-a", (QueryProfileRegistry) null);
far.set("a", "far-a", (QueryProfileRegistry) null);
barn.set("a", "barn-a", (QueryProfileRegistry) null);
mormor.set("b", "mormor-b", (QueryProfileRegistry) null);
far.set("b", "far-b", (QueryProfileRegistry) null);
mor.set("c", "mor-c", (QueryProfileRegistry) null);
far.set("c", "far-c", (QueryProfileRegistry) null);
CompiledQueryProfile cbarn = barn.compile(null);
QueryProfileProperties properties = new QueryProfileProperties(cbarn);
assertEquals("barn-a", cbarn.get("a"));
assertEquals("mormor-b", cbarn.get("b"));
Map<String, Object> rootMap = properties.listProperties();
assertEquals("barn-a", rootMap.get("a"));
assertEquals("mormor-b", rootMap.get("b"));
assertEquals("mor-c", rootMap.get("c"));
Map<String, Object> modelMap = properties.listProperties("model");
assertEquals("mormor-model.b", modelMap.get("b"));
QueryProfile annetBarn = new QueryProfile("annetBarn");
annetBarn.set("venn", barn, (QueryProfileRegistry) null);
CompiledQueryProfile cannetBarn = annetBarn.compile(null);
Map<String, Object> annetBarnMap = new QueryProfileProperties(cannetBarn).listProperties();
assertEquals("barn-a", annetBarnMap.get("venn.a"));
assertEquals("mormor-b", annetBarnMap.get("venn.b"));
assertEquals("mor-c", annetBarnMap.get("venn.c"));
assertEquals("mormor-model.b", annetBarnMap.get("venn.model.b"));
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile in project vespa by vespa-engine.
the class QueryProfileTestCase method testInheritance2Level.
public void testInheritance2Level() {
QueryProfile barn = new QueryProfile("barn");
QueryProfile mor = new QueryProfile("mor");
QueryProfile far = new QueryProfile("far");
QueryProfile mormor = new QueryProfile("mormor");
QueryProfile morfar = new QueryProfile("morfar");
QueryProfile farfar = new QueryProfile("farfar");
barn.addInherited(mor);
barn.addInherited(far);
mor.addInherited(mormor);
mor.addInherited(morfar);
far.addInherited(farfar);
morfar.set("a.x", "morfar-a", (QueryProfileRegistry) null);
mormor.set("a.x", "mormor-a", (QueryProfileRegistry) null);
farfar.set("a.x", "farfar-a", (QueryProfileRegistry) null);
mor.set("a.x", "mor-a", (QueryProfileRegistry) null);
far.set("a.x", "far-a", (QueryProfileRegistry) null);
barn.set("a.x", "barn-a", (QueryProfileRegistry) null);
mormor.set("b.x", "mormor-b", (QueryProfileRegistry) null);
far.set("b.x", "far-b", (QueryProfileRegistry) null);
mor.set("c.x", "mor-c", (QueryProfileRegistry) null);
far.set("c.x", "far-c", (QueryProfileRegistry) null);
mor.set("d.a.x", "mor-d.a", (QueryProfileRegistry) null);
barn.set("d.b.x", "barn-d.b", (QueryProfileRegistry) null);
QueryProfile annetBarn = new QueryProfile("annetBarn");
annetBarn.set("venn", barn, (QueryProfileRegistry) null);
CompiledQueryProfile cbarn = barn.compile(null);
CompiledQueryProfile cannetBarn = annetBarn.compile(null);
assertEquals("barn-a", cbarn.get("a.x"));
assertEquals("mormor-b", cbarn.get("b.x"));
assertEquals("mor-c", cbarn.get("c.x"));
assertEquals("barn-a", cannetBarn.get("venn.a.x"));
assertEquals("mormor-b", cannetBarn.get("venn.b.x"));
assertEquals("mor-c", cannetBarn.get("venn.c.x"));
assertEquals("barn-d.b", cbarn.get("d.b.x"));
assertEquals("mor-d.a", cbarn.get("d.a.x"));
}
Aggregations