diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-03-11 10:43:35 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-03-11 10:43:35 +0100 |
commit | 53692c98aedf03af444a339be389b372b49bee18 (patch) | |
tree | d0bedc47f9fd028f051b4974e0963a2ab0936dc3 /container-search | |
parent | d8aba5c8b45ec3871eb808b8b69cbe76b4f409b8 (diff) |
Support equiv
Diffstat (limited to 'container-search')
8 files changed, 43 insertions, 26 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json index 705318cb8de..b9340636841 100644 --- a/container-search/abi-spec.json +++ b/container-search/abi-spec.json @@ -1558,6 +1558,7 @@ "public static com.yahoo.prelude.query.TermType OR", "public static com.yahoo.prelude.query.TermType NOT", "public static com.yahoo.prelude.query.TermType PHRASE", + "public static com.yahoo.prelude.query.TermType EQUIV", "public static com.yahoo.prelude.query.TermType DEFAULT", "public final java.lang.String name" ] diff --git a/container-search/src/main/java/com/yahoo/prelude/query/TermType.java b/container-search/src/main/java/com/yahoo/prelude/query/TermType.java index a0467703b13..b818e916e71 100644 --- a/container-search/src/main/java/com/yahoo/prelude/query/TermType.java +++ b/container-search/src/main/java/com/yahoo/prelude/query/TermType.java @@ -20,6 +20,8 @@ public class TermType { public static TermType PHRASE = new TermType("phrase", PhraseItem.class, null, "\""); + public static TermType EQUIV = new TermType("equiv", EquivItem.class, null, ""); + public static TermType DEFAULT = new TermType("", CompositeItem.class, AndItem.class, ""); public final String name; @@ -57,8 +59,7 @@ public class TermType { * Returns an instance of the class corresponding to the given type, AndItem * if this is the DEFAULT type * - * @throws RuntimeException - * if an instance could not be created + * @throws RuntimeException if an instance could not be created */ public Item createItemClass() { try { diff --git a/container-search/src/main/java/com/yahoo/prelude/searcher/FieldCollapsingSearcher.java b/container-search/src/main/java/com/yahoo/prelude/searcher/FieldCollapsingSearcher.java index badb99c0523..709d9459e50 100644 --- a/container-search/src/main/java/com/yahoo/prelude/searcher/FieldCollapsingSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/searcher/FieldCollapsingSearcher.java @@ -22,7 +22,6 @@ import java.util.Map; * * @author Steinar Knutsen */ -@SuppressWarnings("deprecation") @After(PhaseNames.RAW_QUERY) @Before(PhaseNames.TRANSFORMED_QUERY) public class FieldCollapsingSearcher extends Searcher { @@ -33,7 +32,7 @@ public class FieldCollapsingSearcher extends Searcher { private static final CompoundName collapseSummaryName = new CompoundName("collapse.summary"); /** Maximum number of queries to send next searcher */ - private int maxQueries = 4; + private final int maxQueries = 4; /** * The max number of hits that will be preserved per unique diff --git a/container-search/src/main/java/com/yahoo/prelude/semantics/engine/Evaluation.java b/container-search/src/main/java/com/yahoo/prelude/semantics/engine/Evaluation.java index dafc31c66fa..b1b317379ff 100644 --- a/container-search/src/main/java/com/yahoo/prelude/semantics/engine/Evaluation.java +++ b/container-search/src/main/java/com/yahoo/prelude/semantics/engine/Evaluation.java @@ -21,7 +21,7 @@ public class Evaluation { // TODO: Retrofit query into the namespace construct private ParameterNameSpace parameterNameSpace = null; - private Query query; + private final Query query; /** The current index into the flattened item list */ private int currentIndex = 0; @@ -30,7 +30,7 @@ public class Evaluation { private List<FlattenedItem> flattenedItems; /** The rule evaluation context, can be reset once the rule is evaluated */ - private RuleEvaluation ruleEvaluation; + private final RuleEvaluation ruleEvaluation; /** * The amount of context information to collect about this evaluation. @@ -41,7 +41,7 @@ public class Evaluation { private String traceIndentation = ""; /** See RuleEngine */ - private Set<Integer> matchDigests = new HashSet<>(); + private final Set<Integer> matchDigests = new HashSet<>(); /** The previous size of this query (see RuleEngine), set on matches only */ private int previousQuerySize = 0; @@ -373,25 +373,15 @@ public class Evaluation { } private CompositeItem createType(TermType termType) { - if (termType==TermType.DEFAULT) { - if (query.getModel().getType().equals(Query.Type.ANY)) + if (termType == TermType.DEFAULT) { + if (query.getModel().getType() == Query.Type.ANY) return new OrItem(); else return new AndItem(); } - else if (termType==TermType.AND) { - return new AndItem(); - } - else if (termType==TermType.OR) { - return new OrItem(); - } - else if (termType==TermType.RANK) { - return new RankItem(); - } - else if (termType==TermType.NOT) { - return new NotItem(); + else { + return (CompositeItem)termType.createItemClass(); } - throw new IllegalArgumentException("Programing error, this method should be updated with add in RankType"); } private void flatten(Item item,int position,List<FlattenedItem> toList) { diff --git a/container-search/src/main/javacc/com/yahoo/prelude/semantics/parser/SemanticsParser.jj b/container-search/src/main/javacc/com/yahoo/prelude/semantics/parser/SemanticsParser.jj index 3a82ffffb47..24fae895364 100644 --- a/container-search/src/main/javacc/com/yahoo/prelude/semantics/parser/SemanticsParser.jj +++ b/container-search/src/main/javacc/com/yahoo/prelude/semantics/parser/SemanticsParser.jj @@ -310,6 +310,7 @@ TermType termType() : <DOLLAR> { return TermType.RANK; } | <PLUS> { return TermType.AND; } | <DASH> { return TermType.NOT; } | + <EQUALS> { return TermType.EQUIV; } | { return TermType.DEFAULT; } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExpansionTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExpansionTestCase.java new file mode 100644 index 00000000000..b2d0d60c8fa --- /dev/null +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExpansionTestCase.java @@ -0,0 +1,22 @@ +// Copyright Verizon Media. 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; + +public class ExpansionTestCase extends RuleBaseAbstractTestCase { + + public ExpansionTestCase() { + super("expansion.sr"); + } + + @Test + public void testOrExpansion() { + assertSemantics("OR or1 or2 or3", "or1"); + } + + @Test + public void testEquivExpansion() { + assertSemantics("EQUIV equiv1 equiv2 equiv3", "equiv1"); + } + +} diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java index b7754075724..5e5df9d2005 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java @@ -151,7 +151,7 @@ public class SemanticSearcherTestCase extends RuleBaseAbstractTestCase { @Test public void testOrProduction() { - assertSemantics("OR something somethingelse","something"); + assertSemantics("OR something somethingelse", "something"); } // This test is order dependent. Fix it!! @@ -159,15 +159,15 @@ public class SemanticSearcherTestCase extends RuleBaseAbstractTestCase { public void testWeightedSetItem() { Query q = new Query(); WeightedSetItem weightedSet=new WeightedSetItem("fieldName"); - weightedSet.addToken("a",1); - weightedSet.addToken("b",2); + weightedSet.addToken("a", 1); + weightedSet.addToken("b", 2); q.getModel().getQueryTree().setRoot(weightedSet); - assertSemantics("WEIGHTEDSET fieldName{[1]:\"a\",[2]:\"b\"}",q); + assertSemantics("WEIGHTEDSET fieldName{[1]:\"a\",[2]:\"b\"}", q); } @Test public void testNullQuery() { - Query query=new Query(""); // Causes a query containing a NullItem + Query query = new Query(""); // Causes a query containing a NullItem doSearch(searcher, query, 0, 10); assertEquals(NullItem.class, query.getModel().getQueryTree().getRoot().getClass()); // Still a NullItem } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/rulebases/expansion.sr b/container-search/src/test/java/com/yahoo/prelude/semantics/test/rulebases/expansion.sr new file mode 100644 index 00000000000..c81b0e1819e --- /dev/null +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/rulebases/expansion.sr @@ -0,0 +1,3 @@ +or1 +> ?or2 ?or3; + +equiv1 +> =equiv2 =equiv3; |