Search in sources :

Example 6 with QueryProfile

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

the class QueryProfilesTestCase method testQueryProfiles.

@Test
public void testQueryProfiles() throws IOException {
    final boolean mandatory = true;
    final boolean overridable = true;
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfileTypeRegistry typeRegistry = registry.getTypeRegistry();
    QueryProfileType userType = new QueryProfileType("user");
    userType.setStrict(true);
    userType.addField(new FieldDescription("robot", FieldType.fromString("boolean", typeRegistry), "machine automaton", mandatory, !overridable));
    userType.addField(new FieldDescription("ads", FieldType.fromString("string", typeRegistry), mandatory, overridable));
    userType.addField(new FieldDescription("age", FieldType.fromString("integer", typeRegistry), !mandatory, overridable));
    typeRegistry.register(userType);
    QueryProfileType rootType = new QueryProfileType("root");
    QueryProfileType nativeProfile = typeRegistry.getComponent("native");
    assertNotNull(nativeProfile);
    assertTrue(nativeProfile.isBuiltin());
    rootType.inherited().add(nativeProfile);
    rootType.setMatchAsPath(true);
    rootType.addField(new FieldDescription("user", FieldType.fromString("query-profile:user", typeRegistry), mandatory, overridable));
    typeRegistry.register(rootType);
    QueryProfileType marketType = new QueryProfileType("market");
    marketType.inherited().add(rootType);
    marketType.addField(new FieldDescription("market", FieldType.fromString("string", typeRegistry), !mandatory, !overridable));
    typeRegistry.register(marketType);
    QueryProfile defaultProfile = new QueryProfile("default");
    defaultProfile.set("ranking", "production23", registry);
    defaultProfile.set("representation.defaultIndex", "title", registry);
    defaultProfile.setOverridable("representation.defaultIndex", false, null);
    registry.register(defaultProfile);
    QueryProfile test = new QueryProfile("test");
    test.set("tracelevel", 2, registry);
    registry.register(test);
    QueryProfile genericUser = new QueryProfile("genericUser");
    genericUser.setType(userType);
    genericUser.set("robot", false, registry);
    genericUser.set("ads", "all", registry);
    registry.register(genericUser);
    QueryProfile root = new QueryProfile("root");
    root.setType(rootType);
    root.addInherited(defaultProfile);
    root.addInherited(test);
    root.set("hits", 30, registry);
    root.setOverridable("hits", false, null);
    root.set("unique", "category", registry);
    root.set("user", genericUser, registry);
    root.set("defaultage", "7d", registry);
    registry.register(root);
    QueryProfile marketUser = new QueryProfile("marketUser");
    marketUser.setType(userType);
    marketUser.addInherited(genericUser);
    marketUser.set("ads", "none", registry);
    marketUser.set("age", 25, registry);
    registry.register(marketUser);
    QueryProfile market = new QueryProfile("root/market");
    market.setType(marketType);
    market.addInherited(root);
    market.set("hits", 15, registry);
    market.set("user", marketUser, registry);
    market.set("market", "some market", registry);
    market.set("marketHeading", "Market of %{market}", registry);
    registry.register(market);
    QueryProfile untypedUser = new QueryProfile("untypedUser");
    untypedUser.set("robot", false, registry);
    untypedUser.set("robot.type", "continent-class", registry);
    registry.register(untypedUser);
    assertConfig("query-profiles.cfg", registry);
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryProfileTypeRegistry(com.yahoo.search.query.profile.types.QueryProfileTypeRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription) Test(org.junit.Test)

Example 7 with QueryProfile

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

the class XmlReadingTestCase method testBasicsWithProfile.

@Test
public void testBasicsWithProfile() {
    QueryProfile p = new QueryProfile("default");
    p.set("a", "foo", null);
    Query q = new Query(HttpRequest.createTestRequest("?query=test", Method.GET), p.compile(null));
    assertEquals("test", q.properties().get("query"));
    assertEquals("test", q.properties().get("QueRY"));
    assertEquals("test", q.properties().get("model.queryString"));
    assertEquals("test", q.getModel().getQueryString());
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) Test(org.junit.Test)

Example 8 with QueryProfile

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

the class FederationSearcherTestCase method assertSelects.

private void assertSelects(String providerName, SearchChainRegistry registry) {
    QueryProfile profile = new QueryProfile("test");
    profile.set("source.news.provider", providerName, null);
    Query query = new Query(QueryTestCase.httpEncode("?query=test&model.sources=news"), profile.compile(null));
    Result result = new Execution(registry.getComponent("default"), Execution.Context.createContextStub(registry, null)).search(query);
    assertEquals(1, result.hits().size());
    assertNotNull(result.hits().get(providerName + ":1"));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result)

Example 9 with QueryProfile

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

the class QueryProfileXMLReader method createQueryProfiles.

public List<Element> createQueryProfiles(List<NamedReader> queryProfileReaders, QueryProfileRegistry registry) {
    List<Element> queryProfileElements = new ArrayList<>(queryProfileReaders.size());
    for (NamedReader reader : queryProfileReaders) {
        Element root = XML.getDocument(reader).getDocumentElement();
        if (!root.getNodeName().equals("query-profile")) {
            throw new IllegalArgumentException("Root tag in '" + reader.getName() + "' must be 'query-profile', not '" + root.getNodeName() + "'");
        }
        String idString = root.getAttribute("id");
        if (idString == null || idString.equals(""))
            throw new IllegalArgumentException("Query profile '" + reader.getName() + "' has no 'id' attribute in the root element");
        ComponentId id = new ComponentId(idString);
        validateFileNameToId(reader.getName(), id, "query profile");
        QueryProfile queryProfile = new QueryProfile(id);
        String typeId = root.getAttribute("type");
        if (typeId != null && !typeId.equals("")) {
            QueryProfileType type = registry.getType(typeId);
            if (type == null)
                throw new IllegalArgumentException("Query profile '" + reader.getName() + "': Type id '" + typeId + "' can not be resolved");
            queryProfile.setType(type);
        }
        Element dimensions = XML.getChild(root, "dimensions");
        if (dimensions != null)
            queryProfile.setDimensions(toArray(XML.getValue(dimensions)));
        registry.register(queryProfile);
        queryProfileElements.add(root);
    }
    return queryProfileElements;
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NamedReader(com.yahoo.io.reader.NamedReader) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) ComponentId(com.yahoo.component.ComponentId)

Example 10 with QueryProfile

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

the class QueryProfileXMLReader method fillQueryProfiles.

public void fillQueryProfiles(List<Element> queryProfileElements, QueryProfileRegistry registry) {
    for (Element element : queryProfileElements) {
        // Lookup by exact id
        QueryProfile profile = registry.getComponent(new ComponentSpecification(element.getAttribute("id")).toId());
        try {
            readInherited(element, profile, registry, null, profile.toString());
            readFields(element, profile, registry, null, profile.toString());
            readVariants(element, profile, registry);
        } catch (RuntimeException e) {
            throw new IllegalArgumentException("Error reading " + profile, e);
        }
    }
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) ComponentSpecification(com.yahoo.component.ComponentSpecification) Element(org.w3c.dom.Element)

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