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"));
}
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;
}
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();
}
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());
}
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;
}
Aggregations