use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class SearchBuilder method createFromDirectory.
public static SearchBuilder createFromDirectory(String dir, RankProfileRegistry rankProfileRegistry, QueryProfileRegistry queryProfileRegistry) throws IOException, ParseException {
SearchBuilder builder = new SearchBuilder(MockApplicationPackage.fromSearchDefinitionDirectory(dir), rankProfileRegistry, queryProfileRegistry);
for (Iterator<Path> i = Files.list(new File(dir).toPath()).filter(p -> p.getFileName().toString().endsWith(".sd")).iterator(); i.hasNext(); ) {
builder.importFile(i.next());
}
builder.build(true, new BaseDeployLogger());
return builder;
}
use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class EmptyRankProfileTestCase method testDeriving.
@Test
public void testDeriving() {
Search search = new Search("test", null);
RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(search);
SDDocumentType doc = new SDDocumentType("test");
search.addDocument(doc);
doc.addField(new SDField("a", DataType.STRING));
SDField field = new SDField("b", DataType.STRING);
field.setLiteralBoost(500);
doc.addField(field);
doc.addField(new SDField("c", DataType.STRING));
search = SearchBuilder.buildFromRawSearch(search, rankProfileRegistry, new QueryProfileRegistry());
new DerivedConfiguration(search, rankProfileRegistry, new QueryProfileRegistry());
}
use of com.yahoo.search.query.profile.QueryProfileRegistry 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());
}
use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class RankingExpressionValidationTestCase method assertFailsExpression.
private void assertFailsExpression(String expression) throws ParseException {
try {
RankProfileRegistry registry = new RankProfileRegistry();
Search search = importWithExpression(expression, registry);
// cause rank profile parsing
new DerivedConfiguration(search, registry, new QueryProfileRegistry());
fail("No exception on incorrect ranking expression " + expression);
} catch (IllegalArgumentException e) {
// Success
// TODO: Where's the "com.yahoo.searchdefinition.parser.ParseException:" nonsense coming from?
assertTrue("Got unexpected error message: " + e.getCause().getMessage(), e.getCause().getMessage().startsWith("com.yahoo.searchdefinition.parser.ParseException: Could not parse ranking expression '" + expression + "'"));
}
}
use of com.yahoo.search.query.profile.QueryProfileRegistry in project vespa by vespa-engine.
the class RankProfileTestCase 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(tensor1)", FieldType.fromString("tensor(x[10])", typeRegistry)), typeRegistry);
type.addField(new FieldDescription("ranking.features.query(tensor2)", FieldType.fromString("tensor(y{})", typeRegistry)), typeRegistry);
type.addField(new FieldDescription("ranking.features.invalid(tensor3)", FieldType.fromString("tensor(x{})", typeRegistry)), typeRegistry);
type.addField(new FieldDescription("ranking.features.query(numeric)", FieldType.fromString("integer", typeRegistry)), typeRegistry);
typeRegistry.register(type);
return registry;
}
Aggregations