diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-01-11 18:45:55 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-01-11 18:45:55 +0100 |
commit | 2627f74bff87b619393cf74fe36228c9cb5ad4ed (patch) | |
tree | bdc8ccd44553f9b2fb26cac06286fdbc24a27323 /container-search/src/main/java/com/yahoo/prelude/semantics/rule | |
parent | 77f8677d12f3cc3013e3c1cca9469e05abf9edae (diff) |
Propagate the original term in the evaluation
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/semantics/rule')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermCondition.java | 22 | ||||
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermProduction.java | 4 |
2 files changed, 7 insertions, 19 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermCondition.java b/container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermCondition.java index 6e2d3de7d08..a2bbf72a53b 100644 --- a/container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermCondition.java +++ b/container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermCondition.java @@ -14,8 +14,8 @@ import com.yahoo.prelude.semantics.engine.RuleEvaluation; public class TermCondition extends Condition { private final RuleBaseLinguistics linguistics; - private String originalTerm; - private String term; + private final String originalTerm; + private final String term; public TermCondition(String term, RuleBaseLinguistics linguistics) { this(null, term, linguistics); @@ -28,12 +28,6 @@ public class TermCondition extends Condition { this.term = linguistics.process(term); } - public String getTerm() { return term; } - - public void setTerm(String term) { - this.term = term; - } - protected boolean doesMatch(RuleEvaluation e) { // TODO: Move this into the respective namespaces when query becomes one */ if (getNameSpace() != null) { @@ -44,10 +38,10 @@ public class TermCondition extends Condition { if (e.currentItem() == null) return false; if ( ! labelMatches(e)) return false; - String matchedValue = termMatches(e.currentItem().getItem()); - boolean matches = matchedValue!=null && labelMatches(e.currentItem().getItem(), e); + boolean matches = labelMatches(e.currentItem().getItem(), e) && + linguistics.process(e.currentItem().getItem().stringValue()).equals(term); if ((matches && !e.isInNegation() || (!matches && e.isInNegation()))) { - e.addMatch(e.currentItem(), matchedValue); + e.addMatch(e.currentItem(), originalTerm); e.setValue(term); e.next(); } @@ -55,12 +49,6 @@ public class TermCondition extends Condition { } } - /** Returns a non-null replacement term if there is a match, null otherwise */ - private String termMatches(TermItem queryTerm) { - boolean matches = linguistics.process(queryTerm.stringValue()).equals(term); - return matches ? term : null; - } - public String toInnerString() { return getLabelString() + term; } diff --git a/container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermProduction.java b/container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermProduction.java index db8d4b42521..29e4982ac17 100644 --- a/container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermProduction.java +++ b/container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermProduction.java @@ -15,7 +15,7 @@ import com.yahoo.protect.Validator; public abstract class TermProduction extends Production { /** The label of this term, or null if none */ - private String label = null; + private String label; /** The type of term to produce */ private TermType termType; @@ -62,7 +62,7 @@ public abstract class TermProduction extends Production { protected void insertMatch(RuleEvaluation e, Match matched, Item newItem, int offset) { if (getWeight() != 100) newItem.setWeight(getWeight()); - int insertPosition = matched.getPosition()+offset; + int insertPosition = matched.getPosition() + offset; // This check is necessary (?) because earlier items may have been removed // after we recorded the match position. It is sort of hackish. A cleaner |