Search in sources :

Example 16 with QueryProfileRegistry

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

the class RankPropertiesTestCase method testRankPropertyInheritance.

@Test
public void testRankPropertyInheritance() 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 parent {\n" + "        first-phase {\n" + "            expression: a\n" + "        }\n" + "        rank-properties {\n" + "            query(a): 1500 \n" + "        }\n" + "    }\n" + "    rank-profile child inherits parent {\n" + "        first-phase {\n" + "            expression: a\n" + "        }\n" + "        rank-properties {\n" + "            query(a): 2000 \n" + "        }\n" + "    }\n" + "\n" + "}\n");
    builder.build();
    Search search = builder.getSearch();
    AttributeFields attributeFields = new AttributeFields(search);
    {
        // Check declared model
        RankProfile parent = rankProfileRegistry.getRankProfile(search, "parent");
        assertEquals("query(a) = 1500", parent.getRankProperties().get(0).toString());
        // Check derived model
        RawRankProfile rawParent = new RawRankProfile(parent, new QueryProfileRegistry(), attributeFields);
        assertEquals("(query(a),1500)", rawParent.configProperties().get(0).toString());
    }
    {
        // Check declared model
        RankProfile parent = rankProfileRegistry.getRankProfile(search, "child");
        assertEquals("query(a) = 2000", parent.getRankProperties().get(0).toString());
        // Check derived model
        RawRankProfile rawChild = new RawRankProfile(rankProfileRegistry.getRankProfile(search, "child"), new QueryProfileRegistry(), attributeFields);
        assertEquals("(query(a),2000)", rawChild.configProperties().get(0).toString());
    }
}
Also used : RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) AttributeFields(com.yahoo.searchdefinition.derived.AttributeFields) RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) Test(org.junit.Test)

Example 17 with QueryProfileRegistry

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

the class RankingExpressionConstantsTestCase method testNameCollision.

@Test
public void testNameCollision() 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" + "        constants {\n" + "            c: 7 \n" + "        }\n" + "        macro c() {\n" + "            expression: p2*p1\n" + "        }\n" + "    }\n" + "\n" + "}\n");
    builder.build();
    Search s = builder.getSearch();
    try {
        rankProfileRegistry.getRankProfile(s, "test").compile(new QueryProfileRegistry());
        fail("Should have caused an exception");
    } catch (IllegalArgumentException e) {
        assertEquals("Rank profile 'test' is invalid: Cannot have both a constant and macro named 'c'", Exceptions.toMessageString(e));
    }
}
Also used : QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) Test(org.junit.Test)

Example 18 with QueryProfileRegistry

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

the class RankingExpressionConstantsTestCase method testNegativeConstantArgument.

@Test
public void testNegativeConstantArgument() 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" + "        constants {\n" + "            myValue: -9.21034037\n" + "        }\n" + "        macro POP_SLOW_SCORE() {\n" + "            expression:  safeLog(popShareSlowDecaySignal, myValue)\n" + "        }\n" + "    }\n" + "\n" + "}\n");
    builder.build();
    Search s = builder.getSearch();
    RankProfile profile = rankProfileRegistry.getRankProfile(s, "test");
    // TODO: Do differently
    profile.parseExpressions();
    assertEquals("safeLog(popShareSlowDecaySignal,myValue)", profile.getMacros().get("POP_SLOW_SCORE").getRankingExpression().getRoot().toString());
    assertEquals("safeLog(popShareSlowDecaySignal,-9.21034037)", profile.compile(new QueryProfileRegistry()).getMacros().get("POP_SLOW_SCORE").getRankingExpression().getRoot().toString());
}
Also used : QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) Test(org.junit.Test)

Example 19 with QueryProfileRegistry

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

the class RankingExpressionShadowingTestCase method testMacroShadowingArguments.

@Test
public void testMacroShadowingArguments() 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: cos(sin(2*2)) + sin(cos(1+4))\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,4.0 * 4.0)", censorBindingHash(testRankProperties.get(1).toString()));
    assertEquals("(rankingExpression(sin@).rankingScript,cos(5.0) * cos(5.0))", censorBindingHash(testRankProperties.get(2).toString()));
    assertEquals("(vespa.rank.firstphase,rankingExpression(firstphase))", censorBindingHash(testRankProperties.get(3).toString()));
    assertEquals("(rankingExpression(firstphase).rankingScript,cos(rankingExpression(sin@)) + rankingExpression(sin@))", censorBindingHash(testRankProperties.get(4).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 20 with QueryProfileRegistry

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

the class RankingExpressionShadowingTestCase method testMultiLevelMacroShadowing.

@Test
public void testMultiLevelMacroShadowing() 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 tan(x) {\n" + "            expression: x * x\n" + "        }\n" + "        macro cos(x) {\n" + "            expression: tan(x)\n" + "        }\n" + "        macro sin(x) {\n" + "            expression: cos(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(tan).rankingScript,x * x)", testRankProperties.get(0).toString());
    assertEquals("(rankingExpression(tan@).rankingScript,x * x)", censorBindingHash(testRankProperties.get(1).toString()));
    assertEquals("(rankingExpression(cos).rankingScript,rankingExpression(tan@))", censorBindingHash(testRankProperties.get(2).toString()));
    assertEquals("(rankingExpression(cos@).rankingScript,rankingExpression(tan@))", censorBindingHash(testRankProperties.get(3).toString()));
    assertEquals("(rankingExpression(sin).rankingScript,rankingExpression(cos@))", censorBindingHash(testRankProperties.get(4).toString()));
    assertEquals("(rankingExpression(tan@).rankingScript,2 * 2)", censorBindingHash(testRankProperties.get(5).toString()));
    assertEquals("(rankingExpression(cos@).rankingScript,rankingExpression(tan@))", censorBindingHash(testRankProperties.get(6).toString()));
    assertEquals("(rankingExpression(sin@).rankingScript,rankingExpression(cos@))", censorBindingHash(testRankProperties.get(7).toString()));
    assertEquals("(vespa.rank.firstphase,rankingExpression(sin@))", censorBindingHash(testRankProperties.get(8).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)

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