diff options
Diffstat (limited to 'container-search')
4 files changed, 45 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 diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/MusicTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MusicTestCase.java new file mode 100644 index 00000000000..006dcb3c714 --- /dev/null +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MusicTestCase.java @@ -0,0 +1,19 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.prelude.semantics.test; + +import org.junit.Test; + +/** + * Tests the rewriting in the semanticsearcher system test + * + * @author bratseth + */ +public class MusicTestCase { + + @Test + public void testMusic() { + var tester = new RuleBaseTester("music.sr"); + tester.assertSemantics("AND song:together artist:youngbloods", "together by youngbloods"); + } + +} diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/rulebases/music.sr b/container-search/src/test/java/com/yahoo/prelude/semantics/test/rulebases/music.sr new file mode 100644 index 00000000000..5166a8b8e5d --- /dev/null +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/rulebases/music.sr @@ -0,0 +1,19 @@ +## Some test rules + +# Spelling correction +bahc -> bach; + +# Stopwords +somelongstopword -> ; +[stopword] -> ; +[stopword] :- someotherlongstopword, yetanotherstopword; + +# +[song] by [artist] -> song:[song] artist:[artist]; + +[song] :- together, imagine, tinseltown; +[artist] :- youngbloods, beatles, zappa; + +# Negative +various +> -kingz; + |