Search in sources :

Example 16 with SearchBuilder

use of com.yahoo.searchdefinition.SearchBuilder in project vespa by vespa-engine.

the class ReservedMacroNamesTestCase method requireThatMacrosWithReservedNamesIssueAWarning.

@Test
public void requireThatMacrosWithReservedNamesIssueAWarning() throws ParseException {
    TestDeployLogger deployLogger = new TestDeployLogger();
    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_rank_profile {\n" + "        macro not_a_reserved_name(x) {\n" + "            expression: x + x\n" + "        }\n" + "        macro sigmoid(x) {\n" + "            expression: x * x\n" + "        }\n" + "        first-phase {\n" + "            expression: sigmoid(2) + not_a_reserved_name(1)\n" + "        }\n" + "    }\n" + "    rank-profile test_rank_profile_2 inherits test_rank_profile {\n" + "        macro sin(x) {\n" + "            expression: x * x\n" + "        }\n" + "        first-phase {\n" + "            expression: sigmoid(2) + sin(1)\n" + "        }\n" + "    }\n" + "}\n");
    builder.build(true, deployLogger);
    assertTrue(deployLogger.log.contains("sigmoid") && deployLogger.log.contains("test_rank_profile"));
    assertTrue(deployLogger.log.contains("sigmoid") && deployLogger.log.contains("test_rank_profile_2"));
    assertTrue(deployLogger.log.contains("sin") && deployLogger.log.contains("test_rank_profile_2"));
    assertFalse(deployLogger.log.contains("not_a_reserved_name") && deployLogger.log.contains("test_rank_profile"));
    assertFalse(deployLogger.log.contains("not_a_reserved_name") && deployLogger.log.contains("test_rank_profile_2"));
}
Also used : RankProfileRegistry(com.yahoo.searchdefinition.RankProfileRegistry) SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) Test(org.junit.Test)

Example 17 with SearchBuilder

use of com.yahoo.searchdefinition.SearchBuilder in project vespa by vespa-engine.

the class TensorTransformTestCase method buildSearch.

private List<Pair<String, String>> buildSearch(String expression) throws ParseException {
    RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
    QueryProfileRegistry queryProfiles = setupQueryProfileTypes();
    SearchBuilder builder = new SearchBuilder(rankProfileRegistry, queryProfiles);
    builder.importString("search test {\n" + "    document test { \n" + "        field double_field type double { \n" + "            indexing: summary | attribute \n" + "        }\n" + "        field double_array_field type array<double> { \n" + "            indexing: summary | attribute \n" + "        }\n" + "        field weightedset_field type weightedset<double> { \n" + "            indexing: summary | attribute \n" + "        }\n" + "        field tensor_field_1 type tensor(x{}) { \n" + "            indexing: summary | attribute \n" + "            attribute: tensor(x{}) \n" + "        }\n" + "        field tensor_field_2 type tensor(x[3],y[3]) { \n" + "            indexing: summary | attribute \n" + "            attribute: tensor(x[3],y[3]) \n" + "        }\n" + "    }\n" + "    constant file_constant_tensor {\n" + "        file: constants/tensor.json\n" + "        type: tensor(x{})\n" + "    }\n" + "    rank-profile base {\n" + "        constants {\n" + "            base_constant_tensor {\n" + "                value: { {x:0}:0 }\n" + "            }\n" + "        }\n" + "        macro base_tensor() {\n" + "            expression: constant(base_constant_tensor)\n" + "        }\n" + "    }\n" + "    rank-profile test inherits base {\n" + "        constants {\n" + "            test_constant_tensor {\n" + "                value: { {x:0}:1 }\n" + "            }\n" + "        }\n" + "        macro returns_tensor_with_arg(arg1) {\n" + "            expression: 2.0 * arg1\n" + "        }\n" + "        macro wraps_returns_tensor() {\n" + "            expression: returns_tensor\n" + "        }\n" + "        macro returns_tensor() {\n" + "            expression: attribute(tensor_field_2)\n" + "        }\n" + "        macro tensor_inheriting() {\n" + "            expression: base_tensor\n" + "        }\n" + "        macro testexpression() {\n" + "            expression: " + expression + "\n" + "        }\n" + "    }\n" + "}\n");
    builder.build(true, new BaseDeployLogger());
    Search s = builder.getSearch();
    RankProfile test = rankProfileRegistry.getRankProfile(s, "test").compile(queryProfiles);
    List<Pair<String, String>> testRankProperties = new RawRankProfile(test, queryProfiles, new AttributeFields(s)).configProperties();
    return testRankProperties;
}
Also used : RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) RankProfileRegistry(com.yahoo.searchdefinition.RankProfileRegistry) BaseDeployLogger(com.yahoo.config.model.application.provider.BaseDeployLogger) Search(com.yahoo.searchdefinition.Search) SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) RankProfile(com.yahoo.searchdefinition.RankProfile) RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) AttributeFields(com.yahoo.searchdefinition.derived.AttributeFields) Pair(com.yahoo.collections.Pair)

Example 18 with SearchBuilder

use of com.yahoo.searchdefinition.SearchBuilder in project vespa by vespa-engine.

the class FastAccessValidatorTest method throws_exception_on_incompatible_use_of_fastaccess.

@Test
public void throws_exception_on_incompatible_use_of_fastaccess() throws ParseException {
    SearchBuilder builder = new SearchBuilder(new RankProfileRegistry());
    builder.importString(TestUtil.joinLines("search parent {", "  document parent {", "    field int_field type int { indexing: attribute }", "  }", "}"));
    builder.importString(TestUtil.joinLines("search test {", "    document test { ", "        field int_attribute type int { ", "            indexing: attribute ", "            attribute: fast-access", "        }", "        field predicate_attribute type predicate {", "            indexing: attribute ", "            attribute: fast-access", "        }", "        field tensor_attribute type tensor(x[]) {", "            indexing: attribute ", "            attribute: fast-access", "        }", "        field reference_attribute type reference<parent> {", "            indexing: attribute ", "            attribute: fast-access", "        }", "    }", "}"));
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("For search 'test': The following attributes have a type that is incompatible " + "with fast-access: predicate_attribute, tensor_attribute, reference_attribute. " + "Predicate, tensor and reference attributes are incompatible with fast-access.");
    builder.build();
}
Also used : RankProfileRegistry(com.yahoo.searchdefinition.RankProfileRegistry) SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) Test(org.junit.Test)

Example 19 with SearchBuilder

use of com.yahoo.searchdefinition.SearchBuilder in project vespa by vespa-engine.

the class DocumentGenMojo method execute.

void execute(File sdDir, File outputDir, String packageName) throws MojoFailureException {
    if ("".equals(packageName))
        throw new IllegalArgumentException("You may not use empty package for generated types.");
    searches = new HashMap<String, Search>();
    docTypes = new HashMap<String, String>();
    structTypes = new HashMap<String, String>();
    annotationTypes = new HashMap<String, String>();
    outputDir.mkdirs();
    SearchBuilder builder = buildSearches(sdDir);
    boolean annotationsExported = false;
    for (NewDocumentType docType : builder.getModel().getDocumentManager().getTypes()) {
        if (docType != VespaDocumentType.INSTANCE) {
            exportDocumentSources(outputDir, docType, packageName);
            for (AnnotationType annotationType : docType.getAllAnnotations()) {
                if (provided(annotationType.getName()) != null)
                    continue;
                annotationsExported = true;
                exportAnnotationSources(outputDir, annotationType, docType, packageName);
            }
        }
    }
    exportPackageInfo(outputDir, packageName);
    if (annotationsExported)
        exportPackageInfo(outputDir, packageName + ".annotation");
    exportDocFactory(outputDir, builder.getSearchList(), packageName);
    if (project != null)
        project.addCompileSourceRoot(outputDirectory.toString());
}
Also used : Search(com.yahoo.searchdefinition.Search) UnprocessingSearchBuilder(com.yahoo.searchdefinition.UnprocessingSearchBuilder) SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 20 with SearchBuilder

use of com.yahoo.searchdefinition.SearchBuilder in project vespa by vespa-engine.

the class Deriver method deriveDocuments.

/**
 * Derives only document manager.
 *
 * @param sdFileNames The name of the search definition files to derive from.
 * @param toDir       The directory to write configuration to.
 * @return The list of Search objects, possibly "unproper ones", from sd files containing only document
 */
public static SearchBuilder deriveDocuments(List<String> sdFileNames, String toDir) {
    SearchBuilder builder = getUnprocessingSearchBuilder(sdFileNames);
    DocumentmanagerConfig.Builder documentManagerCfg = new DocumentManager().produce(builder.getModel(), new DocumentmanagerConfig.Builder());
    try {
        DerivedConfiguration.exportDocuments(documentManagerCfg, toDir);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    return builder;
}
Also used : DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) UnprocessingSearchBuilder(com.yahoo.searchdefinition.UnprocessingSearchBuilder) SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) DocumentManager(com.yahoo.vespa.configmodel.producers.DocumentManager) IOException(java.io.IOException)

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