diff options
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermCondition.java')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/semantics/rule/TermCondition.java | 42 |
1 files changed, 20 insertions, 22 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 9baa240fb43..82e64e4229b 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 @@ -12,7 +12,7 @@ import com.yahoo.prelude.semantics.engine.RuleEvaluation; */ public class TermCondition extends Condition { - private String term,termPlusS; + private String term, termPlusS; /** Creates an invalid term */ public TermCondition() { } @@ -21,35 +21,33 @@ public class TermCondition extends Condition { this(null,term); } - public TermCondition(String label,String term) { + public TermCondition(String label, String term) { super(label); - this.term=term; - termPlusS=term + "s"; + this.term = term; + termPlusS = term + "s"; } public String getTerm() { return term; } public void setTerm(String term) { - this.term=term; - termPlusS=term + "s"; + this.term = term; + termPlusS = term + "s"; } protected boolean doesMatch(RuleEvaluation e) { // TODO: Move this into the respective namespaces when query becomes one */ - if (getNameSpace()!=null) { - NameSpace nameSpace=e.getEvaluation().getNameSpace(getNameSpace()); - return nameSpace.matches(term,e); + if (getNameSpace() != null) { + NameSpace nameSpace = e.getEvaluation().getNameSpace(getNameSpace()); + return nameSpace.matches(term, e); } else { - if (e.currentItem()==null) - return false; + if (e.currentItem() == null) return false; + if ( ! labelMatches(e)) return false; - if (!labelMatches(e)) return false; - - String matchedValue=termMatches(e.currentItem().getItem(),e.getEvaluation().getStemming()); - boolean matches=matchedValue!=null && labelMatches(e.currentItem().getItem(),e); + String matchedValue = termMatches(e.currentItem().getItem(), e.getEvaluation().getStemming()); + boolean matches = matchedValue!=null && labelMatches(e.currentItem().getItem(), e); if ((matches && !e.isInNegation() || (!matches && e.isInNegation()))) { - e.addMatch(e.currentItem(),matchedValue); + e.addMatch(e.currentItem(), matchedValue); e.setValue(term); e.next(); } @@ -58,11 +56,11 @@ public class TermCondition extends Condition { } /** Returns a non-null replacement term if there is a match, null otherwise */ - private String termMatches(TermItem queryTerm,boolean stemming){ - String queryTermString=queryTerm.stringValue(); + private String termMatches(TermItem queryTerm, boolean stemming) { + String queryTermString = queryTerm.stringValue(); // The terms are the same - boolean matches=queryTermString.equals(term); + boolean matches = queryTermString.equals(term); if (matches) return term; if (stemming) @@ -72,14 +70,14 @@ public class TermCondition extends Condition { } private boolean termMatchesWithStemming(String queryTermString) { - if (queryTermString.length()<3) return false; // Don't stem very short terms + if (queryTermString.length() < 3) return false; // Don't stem very short terms // The query term minus s is the same - boolean matches=queryTermString.equals(termPlusS); + boolean matches = queryTermString.equals(termPlusS); if (matches) return true; // The query term plus s is the same - matches=term.equals(queryTermString + "s"); + matches = term.equals(queryTermString + "s"); if (matches) return true; return false; |