use of com.yahoo.searchdefinition.SearchBuilder in project vespa by vespa-engine.
the class RankingExpressionTypeValidatorTestCase method tensorFirstPhaseMustProduceDouble.
@Test
public void tensorFirstPhaseMustProduceDouble() throws Exception {
try {
SearchBuilder builder = new SearchBuilder();
builder.importString(joinLines("search test {", " document test { ", " field a type tensor(x[],y[]) {", " indexing: attribute", " }", " }", " rank-profile my_rank_profile {", " first-phase {", " expression: attribute(a)", " }", " }", "}"));
builder.build();
fail("Expected exception");
} catch (IllegalArgumentException expected) {
assertEquals("In search definition 'test', rank profile 'my_rank_profile': The first-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x[],y[])", Exceptions.toMessageString(expected));
}
}
use of com.yahoo.searchdefinition.SearchBuilder in project vespa by vespa-engine.
the class RankingExpressionTypeValidatorTestCase method undeclaredQueryFeaturesAreAccepted.
@Test
public void undeclaredQueryFeaturesAreAccepted() throws Exception {
SearchBuilder builder = new SearchBuilder();
builder.importString(joinLines("search test {", " document test { ", " }", " rank-profile my_rank_profile {", " first-phase {", " expression: query(foo)", " }", " }", "}"));
builder.build();
}
use of com.yahoo.searchdefinition.SearchBuilder in project vespa by vespa-engine.
the class RankingExpressionTypeValidatorTestCase method testTensorMacroInvocationTypes_Nested.
@Test
public void testTensorMacroInvocationTypes_Nested() throws Exception {
SearchBuilder builder = new SearchBuilder();
builder.importString(joinLines("search test {", " document test { ", " field a type tensor(x[],y[]) {", " indexing: attribute", " }", " field b type tensor(z[10]) {", " indexing: attribute", " }", " }", " rank-profile my_rank_profile {", " macro return_a() {", " expression: return_first(attribute(a), attribute(b))", " }", " macro return_b() {", " expression: return_second(attribute(a), attribute(b))", " }", " macro return_first(e1, e2) {", " expression: e1", " }", " macro return_second(e1, e2) {", " expression: return_first(e2, e1)", " }", " summary-features {", " return_a", " return_b", " }", " }", "}"));
builder.build();
RankProfile profile = builder.getRankProfileRegistry().getRankProfile(builder.getSearch(), "my_rank_profile");
assertEquals(TensorType.fromSpec("tensor(x[],y[])"), summaryFeatures(profile).get("return_a").type(profile.typeContext(builder.getQueryProfileRegistry())));
assertEquals(TensorType.fromSpec("tensor(z[10])"), summaryFeatures(profile).get("return_b").type(profile.typeContext(builder.getQueryProfileRegistry())));
}
use of com.yahoo.searchdefinition.SearchBuilder in project vespa by vespa-engine.
the class ReferenceFieldTestCase method reference_fields_are_parsed_from_search_definition.
@Test
public void reference_fields_are_parsed_from_search_definition() throws ParseException {
SearchBuilder builder = new SearchBuilder();
String campaignSdContent = "search campaign {\n" + " document campaign {\n" + " }\n" + "}";
String salespersonSdContent = "search salesperson {\n" + " document salesperson {\n" + " }\n" + "}";
String adSdContent = "search ad {\n" + " document ad {\n" + " field campaign_ref type reference<campaign> { indexing: attribute }\n" + " field salesperson_ref type reference<salesperson> { indexing: attribute }\n" + " }\n" + "}";
builder.importString(campaignSdContent);
builder.importString(salespersonSdContent);
builder.importString(adSdContent);
builder.build();
Search search = builder.getSearch("ad");
assertSearchContainsReferenceField("campaign_ref", "campaign", search.getDocument());
assertSearchContainsReferenceField("salesperson_ref", "salesperson", search.getDocument());
}
use of com.yahoo.searchdefinition.SearchBuilder in project vespa by vespa-engine.
the class ReferenceFieldTestCase method cyclic_document_dependencies_are_detected.
@Test
public void cyclic_document_dependencies_are_detected() throws ParseException {
SearchBuilder builder = new SearchBuilder();
String campaignSdContent = "search campaign {\n" + " document campaign {\n" + " field ad_ref type reference<ad> { indexing: attribute }\n" + " }\n" + "}";
String adSdContent = "search ad {\n" + " document ad {\n" + " field campaign_ref type reference<campaign> { indexing: attribute }\n" + " }\n" + "}";
builder.importString(campaignSdContent);
builder.importString(adSdContent);
exceptionRule.expect(DocumentGraphValidator.DocumentGraphException.class);
exceptionRule.expectMessage("Document dependency cycle detected: campaign->ad->campaign.");
builder.build();
}
Aggregations