use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class RankingExpressionsTestCase method testThatIncludingFileInSubdirFails.
@Test(expected = IllegalArgumentException.class)
public void testThatIncludingFileInSubdirFails() throws IOException, ParseException {
RankProfileRegistry registry = new RankProfileRegistry();
Search search = SearchBuilder.createFromDirectory("src/test/examples/rankingexpressioninfile", registry, new QueryProfileRegistry()).getSearch();
// rank profile parsing happens during deriving
new DerivedConfiguration(search, registry, new QueryProfileRegistry());
}
use of com.yahoo.search.query.profile.QueryProfileRegistry 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());
}
use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class LiteralBoostTestCase method testLiteralBoost.
/**
* Tests adding of literal boost constructs
*/
@Test
public void testLiteralBoost() {
Search search = new Search("literalboost", null);
RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(search);
SDDocumentType document = new SDDocumentType("literalboost");
search.addDocument(document);
SDField field1 = document.addField("a", DataType.STRING);
field1.parseIndexingScript("{ index }");
field1.setLiteralBoost(20);
RankProfile other = new RankProfile("other", search, rankProfileRegistry);
rankProfileRegistry.addRankProfile(other);
other.addRankSetting(new RankProfile.RankSetting("a", RankProfile.RankSetting.Type.LITERALBOOST, 333));
Processing.process(search, new BaseDeployLogger(), rankProfileRegistry, new QueryProfiles(), true);
DerivedConfiguration derived = new DerivedConfiguration(search, rankProfileRegistry, new QueryProfileRegistry());
// Check attribute fields
// TODO: assert content
derived.getAttributeFields();
// Check il script addition
assertIndexing(Arrays.asList("clear_state | guard { input a | tokenize normalize stem:\"SHORTEST\" | index a; }", "clear_state | guard { input a | tokenize | index a_literal; }"), search);
// Check index info addition
IndexInfo indexInfo = derived.getIndexInfo();
assertTrue(indexInfo.hasCommand("a", "literal-boost"));
}
use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class QueryProfileVariantsTestCase method testExplicitReferenceOverride.
/**
* For comparison with the above
*/
@Test
public void testExplicitReferenceOverride() throws IOException {
QueryProfileRegistry registry = new QueryProfileRegistry();
QueryProfile a1 = new QueryProfile("a1");
a1.set("b", "a1.b", registry);
QueryProfile profile = new QueryProfile("test");
profile.set("a", a1, registry);
profile.set("a.b", "a.b", registry);
assertEquals("a.b", profile.get("a.b"));
registry.register(a1);
registry.register(profile);
QueryProfiles profiles = new QueryProfiles(registry);
assertSerializedConfigFileEquals(root + "explicit-reference-override.cfg", profiles.getConfig().toString());
}
use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class QueryProfileVariantsTestCase method testConfigCreationNewsBESimple.
@Test
public void testConfigCreationNewsBESimple() throws IOException {
QueryProfileRegistry registry = new QueryProfileXMLReader().read(root + "newsbesimple");
QueryProfiles profiles = new QueryProfiles(registry);
assertSerializedConfigFileEquals(root + "newsbe-query-profiles-simple.cfg", profiles.getConfig().toString());
}
Aggregations