Search in sources :

Example 91 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class RankingExpressionShadowingTestCase method queryProfileWith.

private QueryProfileRegistry queryProfileWith(String field, String type) {
    QueryProfileType queryProfileType = new QueryProfileType("root");
    queryProfileType.addField(new FieldDescription(field, type));
    QueryProfileRegistry queryProfileRegistry = new QueryProfileRegistry();
    queryProfileRegistry.getTypeRegistry().register(queryProfileType);
    QueryProfile profile = new QueryProfile("default");
    profile.setType(queryProfileType);
    queryProfileRegistry.register(profile);
    return queryProfileRegistry;
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 92 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class QueryProfileXMLReader method readFields.

private void readFields(Element element, QueryProfile profile, QueryProfileRegistry registry, DimensionValues dimensionValues, String sourceDescription) {
    List<KeyValue> references = new ArrayList<>();
    List<KeyValue> properties = new ArrayList<>();
    for (Element field : XML.getChildren(element, "field")) {
        String name = field.getAttribute("name");
        if (name == null || name.equals(""))
            throw new IllegalArgumentException("A field in " + sourceDescription + " has no 'name' attribute");
        try {
            Boolean overridable = getBooleanAttribute("overridable", null, field);
            if (overridable != null)
                profile.setOverridable(name, overridable, null);
            Object fieldValue = readFieldValue(field, name, sourceDescription, registry);
            if (fieldValue instanceof QueryProfile)
                references.add(new KeyValue(name, fieldValue));
            else
                properties.add(new KeyValue(name, fieldValue));
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Invalid field '" + name + "' in " + sourceDescription, e);
        }
    }
    // Must set references before properties
    for (KeyValue keyValue : references) profile.set(keyValue.getKey(), keyValue.getValue(), dimensionValues, registry);
    for (KeyValue keyValue : properties) profile.set(keyValue.getKey(), keyValue.getValue(), dimensionValues, registry);
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 93 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class QueryProfileXMLReader method readInherited.

private void readInherited(Element element, QueryProfile profile, QueryProfileRegistry registry, DimensionValues dimensionValues, String sourceDescription) {
    String inheritedString = element.getAttribute("inherits");
    if (inheritedString == null || inheritedString.equals(""))
        return;
    for (String inheritedId : inheritedString.split(" ")) {
        inheritedId = inheritedId.trim();
        if (inheritedId.equals(""))
            continue;
        QueryProfile inheritedProfile = registry.getComponent(inheritedId);
        if (inheritedProfile == null)
            throw new IllegalArgumentException("Could not resolve inherited query profile '" + inheritedId + "' in " + sourceDescription);
        profile.addInherited(inheritedProfile, dimensionValues);
    }
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile)

Example 94 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class FederationSearcherTestCase method testQueryProfileNestedReferencing.

@Test
public void testQueryProfileNestedReferencing() {
    addChained(new MockSearcher(), "mySource1");
    addChained(new MockSearcher(), "mySource2");
    Chain<Searcher> mainChain = new Chain<>("default", createFederationSearcher());
    QueryProfile defaultProfile = new QueryProfile("default");
    defaultProfile.set("source.mySource1.hits", "%{hits}", null);
    defaultProfile.freeze();
    Query q = new Query(QueryTestCase.httpEncode("?query=test"), defaultProfile.compile(null));
    Result result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(q);
    assertNull(result.hits().getError());
    assertEquals("source:mySource1", result.hits().get(0).getId().stringValue());
    assertEquals("source:mySource2", result.hits().get(1).getId().stringValue());
}
Also used : Chain(com.yahoo.component.chain.Chain) SearchChain(com.yahoo.search.searchchain.SearchChain) QueryProfile(com.yahoo.search.query.profile.QueryProfile) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) FederationSearcher(com.yahoo.search.federation.FederationSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 95 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class QueryTestCase method testQueryPropertyListingThreeLevel.

@Test
public void testQueryPropertyListingThreeLevel() {
    QueryProfile defaultProfile = new QueryProfile("default");
    defaultProfile.setDimensions(new String[] { "x" });
    defaultProfile.set("a.b.c", "a.b.c-x1-value", new String[] { "x1" }, null);
    defaultProfile.set("a.b.c", "a.b.c-x2-value", new String[] { "x2" }, null);
    defaultProfile.freeze();
    {
        Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null));
        Map<String, Object> propertyList = q.properties().listProperties();
        assertEquals(3, propertyList.size());
        assertEquals("a.b.c-x1-value", propertyList.get("a.b.c"));
    }
    {
        Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null));
        Map<String, Object> propertyList = q.properties().listProperties("a");
        assertEquals(1, propertyList.size());
        assertEquals("a.b.c-x1-value", propertyList.get("b.c"));
    }
    {
        Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null));
        Map<String, Object> propertyList = q.properties().listProperties("a.b");
        assertEquals(1, propertyList.size());
        assertEquals("a.b.c-x1-value", propertyList.get("c"));
    }
    {
        Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x2"), defaultProfile.compile(null));
        Map<String, Object> propertyList = q.properties().listProperties();
        assertEquals(3, propertyList.size());
        assertEquals("a.b.c-x2-value", propertyList.get("a.b.c"));
    }
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) Map(java.util.Map) Test(org.junit.Test)

Aggregations

QueryProfile (com.yahoo.search.query.profile.QueryProfile)161 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)92 Query (com.yahoo.search.Query)63 BackedOverridableQueryProfile (com.yahoo.search.query.profile.BackedOverridableQueryProfile)35 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)28 Test (org.junit.Test)26 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)24 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)21 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)12 Properties (com.yahoo.search.query.Properties)8 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 SubstituteString (com.yahoo.search.query.profile.SubstituteString)4 QueryProfilesConfig (com.yahoo.search.query.profile.config.QueryProfilesConfig)4 Element (org.w3c.dom.Element)4 QueryException (com.yahoo.prelude.query.QueryException)3 Properties (com.yahoo.processing.request.Properties)3 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)3 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)3 ComponentSpecification (com.yahoo.component.ComponentSpecification)2