Search in sources :

Example 21 with QueryProfileRegistry

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

the class RankingExpressionShadowingTestCase method testBasicMacroShadowing.

@Test
public void testBasicMacroShadowing() throws ParseException {
    RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
    SearchBuilder builder = new SearchBuilder(rankProfileRegistry);
    builder.importString("search test {\n" + "    document test { \n" + "        field a type string { \n" + "            indexing: index \n" + "        }\n" + "    }\n" + "    \n" + "    rank-profile test {\n" + "        macro sin(x) {\n" + "            expression: x * x\n" + "        }\n" + "        first-phase {\n" + "            expression: sin(2)\n" + "        }\n" + "    }\n" + "\n" + "}\n");
    builder.build();
    Search s = builder.getSearch();
    RankProfile test = rankProfileRegistry.getRankProfile(s, "test").compile(new QueryProfileRegistry());
    List<Pair<String, String>> testRankProperties = new RawRankProfile(test, new QueryProfileRegistry(), new AttributeFields(s)).configProperties();
    assertEquals("(rankingExpression(sin).rankingScript,x * x)", testRankProperties.get(0).toString());
    assertEquals("(rankingExpression(sin@).rankingScript,2 * 2)", censorBindingHash(testRankProperties.get(1).toString()));
    assertEquals("(vespa.rank.firstphase,rankingExpression(sin@))", censorBindingHash(testRankProperties.get(2).toString()));
}
Also used : RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) AttributeFields(com.yahoo.searchdefinition.derived.AttributeFields) Pair(com.yahoo.collections.Pair) Test(org.junit.Test)

Example 22 with QueryProfileRegistry

use of com.yahoo.search.query.profile.QueryProfileRegistry 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 23 with QueryProfileRegistry

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

the class TensorTransformTestCase method buildSearch.

private List<Pair<String, String>> buildSearch(String expression) throws ParseException {
    RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
    QueryProfileRegistry queryProfiles = setupQueryProfileTypes();
    SearchBuilder builder = new SearchBuilder(rankProfileRegistry, queryProfiles);
    builder.importString("search test {\n" + "    document test { \n" + "        field double_field type double { \n" + "            indexing: summary | attribute \n" + "        }\n" + "        field double_array_field type array<double> { \n" + "            indexing: summary | attribute \n" + "        }\n" + "        field weightedset_field type weightedset<double> { \n" + "            indexing: summary | attribute \n" + "        }\n" + "        field tensor_field_1 type tensor(x{}) { \n" + "            indexing: summary | attribute \n" + "            attribute: tensor(x{}) \n" + "        }\n" + "        field tensor_field_2 type tensor(x[3],y[3]) { \n" + "            indexing: summary | attribute \n" + "            attribute: tensor(x[3],y[3]) \n" + "        }\n" + "    }\n" + "    constant file_constant_tensor {\n" + "        file: constants/tensor.json\n" + "        type: tensor(x{})\n" + "    }\n" + "    rank-profile base {\n" + "        constants {\n" + "            base_constant_tensor {\n" + "                value: { {x:0}:0 }\n" + "            }\n" + "        }\n" + "        macro base_tensor() {\n" + "            expression: constant(base_constant_tensor)\n" + "        }\n" + "    }\n" + "    rank-profile test inherits base {\n" + "        constants {\n" + "            test_constant_tensor {\n" + "                value: { {x:0}:1 }\n" + "            }\n" + "        }\n" + "        macro returns_tensor_with_arg(arg1) {\n" + "            expression: 2.0 * arg1\n" + "        }\n" + "        macro wraps_returns_tensor() {\n" + "            expression: returns_tensor\n" + "        }\n" + "        macro returns_tensor() {\n" + "            expression: attribute(tensor_field_2)\n" + "        }\n" + "        macro tensor_inheriting() {\n" + "            expression: base_tensor\n" + "        }\n" + "        macro testexpression() {\n" + "            expression: " + expression + "\n" + "        }\n" + "    }\n" + "}\n");
    builder.build(true, new BaseDeployLogger());
    Search s = builder.getSearch();
    RankProfile test = rankProfileRegistry.getRankProfile(s, "test").compile(queryProfiles);
    List<Pair<String, String>> testRankProperties = new RawRankProfile(test, queryProfiles, new AttributeFields(s)).configProperties();
    return testRankProperties;
}
Also used : RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) RankProfileRegistry(com.yahoo.searchdefinition.RankProfileRegistry) BaseDeployLogger(com.yahoo.config.model.application.provider.BaseDeployLogger) Search(com.yahoo.searchdefinition.Search) SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) RankProfile(com.yahoo.searchdefinition.RankProfile) RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) AttributeFields(com.yahoo.searchdefinition.derived.AttributeFields) Pair(com.yahoo.collections.Pair)

Example 24 with QueryProfileRegistry

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

the class TensorTransformTestCase method setupQueryProfileTypes.

private static QueryProfileRegistry setupQueryProfileTypes() {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfileTypeRegistry typeRegistry = registry.getTypeRegistry();
    QueryProfileType type = new QueryProfileType(new ComponentId("testtype"));
    type.addField(new FieldDescription("ranking.features.query(q)", FieldType.fromString("tensor(x{})", typeRegistry)), typeRegistry);
    type.addField(new FieldDescription("ranking.features.query(n)", FieldType.fromString("integer", typeRegistry)), typeRegistry);
    typeRegistry.register(type);
    return registry;
}
Also used : QueryProfileTypeRegistry(com.yahoo.search.query.profile.types.QueryProfileTypeRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) ComponentId(com.yahoo.component.ComponentId) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 25 with QueryProfileRegistry

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

the class QueryProfileXMLReader method read.

/**
 * Read the XML file readers into a registry. This does not close the readers.
 * This method is used directly from the admin system.
 */
public QueryProfileRegistry read(List<NamedReader> queryProfileTypeReaders, List<NamedReader> queryProfileReaders) {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    // Phase 1
    List<Element> queryProfileTypeElements = createQueryProfileTypes(queryProfileTypeReaders, registry.getTypeRegistry());
    List<Element> queryProfileElements = createQueryProfiles(queryProfileReaders, registry);
    // Phase 2
    fillQueryProfileTypes(queryProfileTypeElements, registry.getTypeRegistry());
    fillQueryProfiles(queryProfileElements, registry);
    return registry;
}
Also used : Element(org.w3c.dom.Element) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry)

Aggregations

QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)68 Test (org.junit.Test)38 QueryProfile (com.yahoo.search.query.profile.QueryProfile)24 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)16 RawRankProfile (com.yahoo.searchdefinition.derived.RawRankProfile)16 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)14 Query (com.yahoo.search.Query)11 AttributeFields (com.yahoo.searchdefinition.derived.AttributeFields)11 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)11 Pair (com.yahoo.collections.Pair)8 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)8 Search (com.yahoo.searchdefinition.Search)8 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)7 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)7 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)6 SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)6 SDField (com.yahoo.searchdefinition.document.SDField)5 ComponentId (com.yahoo.component.ComponentId)4 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)4 QueryProfileTypeRegistry (com.yahoo.search.query.profile.types.QueryProfileTypeRegistry)4