Search in sources :

Example 11 with SearchBuilder

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));
    }
}
Also used : SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) Test(org.junit.Test)

Example 12 with SearchBuilder

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();
}
Also used : SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) Test(org.junit.Test)

Example 13 with SearchBuilder

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())));
}
Also used : SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) RankProfile(com.yahoo.searchdefinition.RankProfile) Test(org.junit.Test)

Example 14 with SearchBuilder

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());
}
Also used : Search(com.yahoo.searchdefinition.Search) SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) Test(org.junit.Test)

Example 15 with SearchBuilder

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();
}
Also used : SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) DocumentGraphValidator(com.yahoo.searchdefinition.DocumentGraphValidator) Test(org.junit.Test)

Aggregations

SearchBuilder (com.yahoo.searchdefinition.SearchBuilder)36 Test (org.junit.Test)24 Search (com.yahoo.searchdefinition.Search)6 UnprocessingSearchBuilder (com.yahoo.searchdefinition.UnprocessingSearchBuilder)6 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)4 IOException (java.io.IOException)4 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)3 RankProfile (com.yahoo.searchdefinition.RankProfile)3 ParseException (com.yahoo.searchdefinition.parser.ParseException)3 File (java.io.File)3 DocumentmanagerConfig (com.yahoo.document.config.DocumentmanagerConfig)2 SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)2 DocumentManager (com.yahoo.vespa.configmodel.producers.DocumentManager)2 Pair (com.yahoo.collections.Pair)1 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)1 DocumenttypesConfig (com.yahoo.document.DocumenttypesConfig)1 AnnotationType (com.yahoo.document.annotation.AnnotationType)1 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)1 DocumentGraphValidator (com.yahoo.searchdefinition.DocumentGraphValidator)1 AttributeFields (com.yahoo.searchdefinition.derived.AttributeFields)1