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());
}
}
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));
}
}
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());
}
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()));
}
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()));
}
Aggregations