Search in sources :

Example 1 with QueryProfileRegistry

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;
}
Also used : Path(java.nio.file.Path) QueryProfiles(com.yahoo.vespa.model.container.search.QueryProfiles) DocumentModel(com.yahoo.vespa.documentmodel.DocumentModel) SDParser(com.yahoo.searchdefinition.parser.SDParser) IOUtils(com.yahoo.io.IOUtils) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) DeployLogger(com.yahoo.config.application.api.DeployLogger) BaseDeployLogger(com.yahoo.config.model.application.provider.BaseDeployLogger) ArrayList(java.util.ArrayList) SearchOrderer(com.yahoo.searchdefinition.derived.SearchOrderer) Processing(com.yahoo.searchdefinition.processing.Processing) TokenMgrError(com.yahoo.searchdefinition.parser.TokenMgrError) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage) Exceptions(com.yahoo.yolean.Exceptions) SimpleCharStream(com.yahoo.searchdefinition.parser.SimpleCharStream) Iterator(java.util.Iterator) Files(java.nio.file.Files) IOException(java.io.IOException) MockApplicationPackage(com.yahoo.config.model.test.MockApplicationPackage) File(java.io.File) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) List(java.util.List) NamedReader(com.yahoo.io.reader.NamedReader) ParseException(com.yahoo.searchdefinition.parser.ParseException) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) BaseDeployLogger(com.yahoo.config.model.application.provider.BaseDeployLogger) File(java.io.File)

Example 2 with QueryProfileRegistry

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());
}
Also used : RankProfileRegistry(com.yahoo.searchdefinition.RankProfileRegistry) SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Search(com.yahoo.searchdefinition.Search) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) Test(org.junit.Test)

Example 3 with 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());
}
Also used : RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) RawRankProfile(com.yahoo.searchdefinition.derived.RawRankProfile) AttributeFields(com.yahoo.searchdefinition.derived.AttributeFields) Pair(com.yahoo.collections.Pair) Test(org.junit.Test)

Example 4 with QueryProfileRegistry

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 + "'"));
    }
}
Also used : DerivedConfiguration(com.yahoo.searchdefinition.derived.DerivedConfiguration) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry)

Example 5 with QueryProfileRegistry

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;
}
Also used : QueryProfileTypeRegistry(com.yahoo.search.query.profile.types.QueryProfileTypeRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) ComponentId(com.yahoo.component.ComponentId) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Aggregations

QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)68 Test (org.junit.Test)38 QueryProfile (com.yahoo.search.query.profile.QueryProfile)24 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)16 RawRankProfile (com.yahoo.searchdefinition.derived.RawRankProfile)16 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)14 Query (com.yahoo.search.Query)11 AttributeFields (com.yahoo.searchdefinition.derived.AttributeFields)11 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)11 Pair (com.yahoo.collections.Pair)8 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)8 Search (com.yahoo.searchdefinition.Search)8 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)7 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)7 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)6 SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)6 SDField (com.yahoo.searchdefinition.document.SDField)5 ComponentId (com.yahoo.component.ComponentId)4 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)4 QueryProfileTypeRegistry (com.yahoo.search.query.profile.types.QueryProfileTypeRegistry)4