diff options
Diffstat (limited to 'config-model')
3 files changed, 57 insertions, 46 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java index 7f3b018d569..85b8d7fbe79 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -674,25 +674,26 @@ public class RankProfile implements Cloneable { inputFeatures.put(ref, declaredType); } - public static class ExecuteOperation { - public enum Phase { onmatch, onrerank, onsummary} + public static class MutateOperation { + public enum Phase { onmatch, on_first_phase, on_second_phase, onsummary} final Phase phase; final String attribute; final String operation; - ExecuteOperation(Phase phase, String attribute, String operation) { + MutateOperation(Phase phase, String attribute, String operation) { this.phase = phase; this.attribute = attribute; this.operation = operation; } } - private final List<ExecuteOperation> executeOperations = new ArrayList<>(); + private final List<MutateOperation> mutateOperations = new ArrayList<>(); - public void addExecuteOperation(ExecuteOperation.Phase phase, String attribute, String operation) { - executeOperations.add(new ExecuteOperation(phase, attribute, operation)); - addRankProperty("vespa.execute." + phase + ".attribute", attribute); - addRankProperty("vespa.execute." + phase + ".operation", operation); + public void addMutateOperation(MutateOperation.Phase phase, String attribute, String operation) { + mutateOperations.add(new MutateOperation(phase, attribute, operation)); + String prefix = "vespa.mutate." + phase.toString().replace('-', '_'); + addRankProperty(prefix + ".attribute", attribute); + addRankProperty(prefix + ".operation", operation); } - public List<ExecuteOperation> getExecuteOperations() { return executeOperations; } + public List<MutateOperation> getMutateOperations() { return mutateOperations; } public RankingExpressionFunction findFunction(String name) { RankingExpressionFunction function = functions.get(name); diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj index 0f60db40069..e6a5d1f2e4e 100644 --- a/config-model/src/main/javacc/SDParser.jj +++ b/config-model/src/main/javacc/SDParser.jj @@ -207,10 +207,10 @@ TOKEN : | < LOOSE: "loose" > | < STRICT: "strict" > | < DOCUMENT: "document" > -| < EXECUTE: "execute" > | < OPERATION: "operation" > | < ON_MATCH: "on-match" > -| < ON_RERANK: "on-rerank" > +| < ON_FIRST_PHASE: "on-first-phase" > +| < ON_SECOND_PHASE: "on-second-phase" > | < ON_SUMMARY: "on-summary" > | < STRUCT: "struct" > | < INHERITS: "inherits" > @@ -239,6 +239,7 @@ TOKEN : | < CONSTANT: "constant"> | < ONNXMODEL: "onnx-model"> | < MODEL: "model" > +| < MUTATE: "mutate" > | < RANKPROFILE: "rank-profile" > | < RANKDEGRADATIONFREQ: "rank-degradation-frequency" > | < RANKDEGRADATION: "rank-degradation" > @@ -2066,7 +2067,7 @@ Object rankProfileItem(RankProfile profile) : { } | firstPhase(profile) | matchPhase(profile) | function(profile) - | execute(profile) + | mutate(profile) | ignoreRankFeatures(profile) | numThreadsPerSearch(profile) | minHitsPerThread(profile) @@ -2096,39 +2097,40 @@ void inheritsRankProfile(RankProfile profile) : } /** - * This rule consumes an execute statement of a rank-profile. + * This rule consumes an mutate statement of a rank-profile. * * @param profile The profile to modify. */ -void execute(RankProfile profile) : +void mutate(RankProfile profile) : { } { - <EXECUTE> lbrace() (execute_operation(profile) <NL>)+ <RBRACE> + <MUTATE> lbrace() (mutate_operation(profile) <NL>)+ <RBRACE> { } } -void execute_operation(RankProfile profile) : +void mutate_operation(RankProfile profile) : { String attribute, operation; - RankProfile.ExecuteOperation.Phase phase; + RankProfile.MutateOperation.Phase phase; } { - ( <ON_MATCH> { phase = RankProfile.ExecuteOperation.Phase.onmatch; } - | <ON_RERANK> { phase = RankProfile.ExecuteOperation.Phase.onrerank; } - | <ON_SUMMARY> { phase = RankProfile.ExecuteOperation.Phase.onsummary; } + ( <ON_MATCH> { phase = RankProfile.MutateOperation.Phase.onmatch; } + | <ON_FIRST_PHASE> { phase = RankProfile.MutateOperation.Phase.on_first_phase; } + | <ON_SECOND_PHASE> { phase = RankProfile.MutateOperation.Phase.on_second_phase; } + | <ON_SUMMARY> { phase = RankProfile.MutateOperation.Phase.onsummary; } ) - lbrace() attribute = identifier() operation = execute_expr() (<NL>)* <RBRACE> - { profile.addExecuteOperation(phase, attribute, operation); } + lbrace() attribute = identifier() operation = mutate_expr() (<NL>)* <RBRACE> + { profile.addMutateOperation(phase, attribute, operation); } } -String execute_expr() : +String mutate_expr() : { String op; Number constant = null; } { - (("++" | "--") { op = token.image; } | ("+=" | "-=" | "*=" | "/=" | "%=" | "=") { op = token.image; } constant = consumeNumber()) + (("+=" | "-=" | "=") { op = token.image; } constant = consumeNumber()) { return constant != null ? (op + constant) : op; } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankPropertiesTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankPropertiesTestCase.java index e2ca8ac4f65..637f7571a68 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankPropertiesTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankPropertiesTestCase.java @@ -78,7 +78,7 @@ public class RankPropertiesTestCase extends AbstractSchemaTestCase { } } @Test - public void testRankProfileExecute() throws ParseException { + public void testRankProfileMutate() throws ParseException { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); SearchBuilder builder = new SearchBuilder(rankProfileRegistry); builder.importString(joinLines( @@ -101,15 +101,18 @@ public class RankPropertiesTestCase extends AbstractSchemaTestCase { " attribute: mutable", " }", " rank-profile a {", - " execute {", + " mutate {", " on-match {", - " synthetic_attribute_a ++", + " synthetic_attribute_a += 7", " }", - " on-rerank {", + " on-first-phase {", + " synthetic_attribute_b +=1", + " }", + " on-second-phase {", " synthetic_attribute_b = 1.01", " }", " on-summary {", - " synthetic_attribute_c --", + " synthetic_attribute_c -= 1", " }", " }", " first-phase {", @@ -128,28 +131,33 @@ public class RankPropertiesTestCase extends AbstractSchemaTestCase { builder.build(); Schema schema = builder.getSearch(); RankProfile a = rankProfileRegistry.get(schema, "a"); - List<RankProfile.ExecuteOperation> operations = a.getExecuteOperations(); - assertEquals(3, operations.size()); - assertEquals(RankProfile.ExecuteOperation.Phase.onmatch, operations.get(0).phase); + List<RankProfile.MutateOperation> operations = a.getMutateOperations(); + assertEquals(4, operations.size()); + assertEquals(RankProfile.MutateOperation.Phase.onmatch, operations.get(0).phase); assertEquals("synthetic_attribute_a", operations.get(0).attribute); - assertEquals("++", operations.get(0).operation); - assertEquals(RankProfile.ExecuteOperation.Phase.onrerank, operations.get(1).phase); + assertEquals("+=7", operations.get(0).operation); + assertEquals(RankProfile.MutateOperation.Phase.on_first_phase, operations.get(1).phase); assertEquals("synthetic_attribute_b", operations.get(1).attribute); - assertEquals("=1.01", operations.get(1).operation); - assertEquals(RankProfile.ExecuteOperation.Phase.onsummary, operations.get(2).phase); - assertEquals("synthetic_attribute_c", operations.get(2).attribute); - assertEquals("--", operations.get(2).operation); + assertEquals("+=1", operations.get(1).operation); + assertEquals(RankProfile.MutateOperation.Phase.on_second_phase, operations.get(2).phase); + assertEquals("synthetic_attribute_b", operations.get(2).attribute); + assertEquals("=1.01", operations.get(2).operation); + assertEquals(RankProfile.MutateOperation.Phase.onsummary, operations.get(3).phase); + assertEquals("synthetic_attribute_c", operations.get(3).attribute); + assertEquals("-=1", operations.get(3).operation); AttributeFields attributeFields = new AttributeFields(schema); RawRankProfile raw = new RawRankProfile(a, new LargeRankExpressions(new MockFileRegistry()), new QueryProfileRegistry(), new ImportedMlModels(), attributeFields, new TestProperties()); - assertEquals(7, raw.configProperties().size()); - assertEquals("(vespa.execute.onmatch.attribute, synthetic_attribute_a)", raw.configProperties().get(0).toString()); - assertEquals("(vespa.execute.onmatch.operation, ++)", raw.configProperties().get(1).toString()); - assertEquals("(vespa.execute.onrerank.attribute, synthetic_attribute_b)", raw.configProperties().get(2).toString()); - assertEquals("(vespa.execute.onrerank.operation, =1.01)", raw.configProperties().get(3).toString()); - assertEquals("(vespa.execute.onsummary.attribute, synthetic_attribute_c)", raw.configProperties().get(4).toString()); - assertEquals("(vespa.execute.onsummary.operation, --)", raw.configProperties().get(5).toString()); - assertEquals("(vespa.rank.firstphase, a)", raw.configProperties().get(6).toString()); + assertEquals(9, raw.configProperties().size()); + assertEquals("(vespa.mutate.onmatch.attribute, synthetic_attribute_a)", raw.configProperties().get(0).toString()); + assertEquals("(vespa.mutate.onmatch.operation, +=7)", raw.configProperties().get(1).toString()); + assertEquals("(vespa.mutate.on_first_phase.attribute, synthetic_attribute_b)", raw.configProperties().get(2).toString()); + assertEquals("(vespa.mutate.on_first_phase.operation, +=1)", raw.configProperties().get(3).toString()); + assertEquals("(vespa.mutate.on_second_phase.attribute, synthetic_attribute_b)", raw.configProperties().get(4).toString()); + assertEquals("(vespa.mutate.on_second_phase.operation, =1.01)", raw.configProperties().get(5).toString()); + assertEquals("(vespa.mutate.onsummary.attribute, synthetic_attribute_c)", raw.configProperties().get(6).toString()); + assertEquals("(vespa.mutate.onsummary.operation, -=1)", raw.configProperties().get(7).toString()); + assertEquals("(vespa.rank.firstphase, a)", raw.configProperties().get(8).toString()); } } |