Search in sources :

Example 1 with CompiledQueryProfile

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());
    }
}
Also used : CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) Query(com.yahoo.search.Query) QueryProfileXMLReader(com.yahoo.search.query.profile.config.QueryProfileXMLReader) Test(org.junit.Test)

Example 2 with CompiledQueryProfile

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;
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) PropertyMap(com.yahoo.processing.request.properties.PropertyMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with CompiledQueryProfile

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"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile)

Example 4 with CompiledQueryProfile

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"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties)

Example 5 with CompiledQueryProfile

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"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile)

Aggregations

CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)48 QueryProfile (com.yahoo.search.query.profile.QueryProfile)37 BackedOverridableQueryProfile (com.yahoo.search.query.profile.BackedOverridableQueryProfile)18 Query (com.yahoo.search.Query)8 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)8 Test (org.junit.Test)7 CompoundName (com.yahoo.processing.request.CompoundName)5 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)4 HashMap (java.util.HashMap)4 HttpRequest (com.yahoo.container.jdisc.HttpRequest)3 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)3 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)3 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)3 Map (java.util.Map)3 QueryProfileConfigurer (com.yahoo.search.query.profile.config.QueryProfileConfigurer)2 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)2 HashSet (java.util.HashSet)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Chain (com.yahoo.component.chain.Chain)1 Renderer (com.yahoo.processing.rendering.Renderer)1