Search in sources :

Example 1 with RawRankProfile

use of com.yahoo.searchdefinition.derived.RawRankProfile in project vespa by vespa-engine.

the class RankingExpressionInliningTestCase method testConstants.

@Test
public void testConstants() 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" + "        constants {\n" + "            p1: 7 \n" + "            p2: 0 \n" + "        }\n" + "        first-phase {\n" + "            expression: p1 + foo\n" + "        }\n" + "        second-phase {\n" + "            expression: p2 * foo\n" + "        }\n" + "        macro inline foo() {\n" + "            expression: 3 + p1 + p2\n" + "        }\n" + "    }\n" + "    rank-profile child inherits parent {\n" + "        first-phase {\n" + "            expression: p1 + foo + baz + bar + arg(4.0)\n" + "        }\n" + "        constants {\n" + "            p2: 2.0 \n" + "        }\n" + "        macro bar() {\n" + "            expression: p2*p1\n" + "        }\n" + "        macro inline baz() {\n" + "            expression: p2+p1+boz\n" + "        }\n" + "        macro inline boz() {\n" + "            expression: 3.0\n" + "        }\n" + "        macro inline arg(a1) {\n" + "            expression: a1*2\n" + "        }\n" + "    }\n" + "\n" + "}\n");
    builder.build();
    Search s = builder.getSearch();
    RankProfile parent = rankProfileRegistry.getRankProfile(s, "parent").compile(new QueryProfileRegistry());
    assertEquals("17.0", parent.getFirstPhaseRanking().getRoot().toString());
    assertEquals("0.0", parent.getSecondPhaseRanking().getRoot().toString());
    List<Pair<String, String>> parentRankProperties = new RawRankProfile(parent, new QueryProfileRegistry(), new AttributeFields(s)).configProperties();
    assertEquals("(rankingExpression(foo).rankingScript,10.0)", parentRankProperties.get(0).toString());
    assertEquals("(rankingExpression(firstphase).rankingScript,17.0)", parentRankProperties.get(2).toString());
    assertEquals("(rankingExpression(secondphase).rankingScript,0.0)", parentRankProperties.get(4).toString());
    RankProfile child = rankProfileRegistry.getRankProfile(s, "child").compile(new QueryProfileRegistry());
    assertEquals("31.0 + bar + arg(4.0)", child.getFirstPhaseRanking().getRoot().toString());
    assertEquals("24.0", child.getSecondPhaseRanking().getRoot().toString());
    List<Pair<String, String>> childRankProperties = new RawRankProfile(child, new QueryProfileRegistry(), new AttributeFields(s)).configProperties();
    assertEquals("(rankingExpression(foo).rankingScript,12.0)", childRankProperties.get(0).toString());
    assertEquals("(rankingExpression(bar).rankingScript,14.0)", childRankProperties.get(1).toString());
    assertEquals("(rankingExpression(boz).rankingScript,3.0)", childRankProperties.get(2).toString());
    assertEquals("(rankingExpression(baz).rankingScript,9.0 + rankingExpression(boz))", childRankProperties.get(3).toString());
    assertEquals("(rankingExpression(arg).rankingScript,a1 * 2)", childRankProperties.get(4).toString());
    assertEquals("(rankingExpression(firstphase).rankingScript,31.0 + rankingExpression(bar) + rankingExpression(arg@))", censorBindingHash(childRankProperties.get(7).toString()));
    assertEquals("(rankingExpression(secondphase).rankingScript,24.0)", childRankProperties.get(9).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 2 with RawRankProfile

use of com.yahoo.searchdefinition.derived.RawRankProfile in project vespa by vespa-engine.

the class RankingExpressionsTestCase method testMacros.

@Test
public void testMacros() throws IOException, ParseException {
    RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
    Search search = SearchBuilder.createFromDirectory("src/test/examples/rankingexpressionfunction", rankProfileRegistry, new QueryProfileRegistry()).getSearch();
    final RankProfile macrosRankProfile = rankProfileRegistry.getRankProfile(search, "macros");
    macrosRankProfile.parseExpressions();
    final Map<String, RankProfile.Macro> macros = macrosRankProfile.getMacros();
    assertEquals(2, macros.get("titlematch$").getFormalParams().size());
    assertEquals("var1", macros.get("titlematch$").getFormalParams().get(0));
    assertEquals("var2", macros.get("titlematch$").getFormalParams().get(1));
    assertEquals("var1 * var2 + 890", macros.get("titlematch$").getTextualExpression().trim());
    assertEquals("var1 * var2 + 890", macros.get("titlematch$").getRankingExpression().getRoot().toString());
    assertEquals("0.8+0.2*titlematch$(4,5)+0.8*titlematch$(7,8)*closeness(distance)", macrosRankProfile.getFirstPhaseRankingString().trim());
    assertEquals("78 + closeness(distance)", macros.get("artistmatch").getTextualExpression().trim());
    assertEquals(0, macros.get("artistmatch").getFormalParams().size());
    List<Pair<String, String>> rankProperties = new RawRankProfile(macrosRankProfile, new QueryProfileRegistry(), new AttributeFields(search)).configProperties();
    assertEquals(6, rankProperties.size());
    assertEquals("rankingExpression(titlematch$).rankingScript", rankProperties.get(0).getFirst());
    assertEquals("var1 * var2 + 890", rankProperties.get(0).getSecond());
    assertEquals("rankingExpression(artistmatch).rankingScript", rankProperties.get(1).getFirst());
    assertEquals("78 + closeness(distance)", rankProperties.get(1).getSecond());
    assertEquals("rankingExpression(firstphase).rankingScript", rankProperties.get(5).getFirst());
    assertEquals("0.8 + 0.2 * rankingExpression(titlematch$@126063073eb2deb.ab95cd69909927c) + 0.8 * rankingExpression(titlematch$@c7e4c2d0e6d9f2a1.1d4ed08e56cce2e6) * closeness(distance)", rankProperties.get(5).getSecond());
    assertEquals("rankingExpression(titlematch$@c7e4c2d0e6d9f2a1.1d4ed08e56cce2e6).rankingScript", rankProperties.get(3).getFirst());
    assertEquals("7 * 8 + 890", rankProperties.get(3).getSecond());
    assertEquals("rankingExpression(titlematch$@126063073eb2deb.ab95cd69909927c).rankingScript", rankProperties.get(2).getFirst());
    assertEquals("4 * 5 + 890", rankProperties.get(2).getSecond());
}
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 3 with RawRankProfile

use of com.yahoo.searchdefinition.derived.RawRankProfile 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 4 with RawRankProfile

use of com.yahoo.searchdefinition.derived.RawRankProfile 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 5 with RawRankProfile

use of com.yahoo.searchdefinition.derived.RawRankProfile 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)12 RawRankProfile (com.yahoo.searchdefinition.derived.RawRankProfile)12 AttributeFields (com.yahoo.searchdefinition.derived.AttributeFields)11 Pair (com.yahoo.collections.Pair)8 Test (org.junit.Test)8 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)1 RankProfile (com.yahoo.searchdefinition.RankProfile)1 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)1 Search (com.yahoo.searchdefinition.Search)1 SearchBuilder (com.yahoo.searchdefinition.SearchBuilder)1