diff options
3 files changed, 43 insertions, 4 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/CompositeItem.java b/container-search/src/main/java/com/yahoo/prelude/query/CompositeItem.java index 602239eb427..2c05f2e7edf 100644 --- a/container-search/src/main/java/com/yahoo/prelude/query/CompositeItem.java +++ b/container-search/src/main/java/com/yahoo/prelude/query/CompositeItem.java @@ -44,7 +44,7 @@ public abstract class CompositeItem extends Item { Item possibleCycle = i.next(); if (this == possibleCycle) { - throw new QueryException("Tried to create a cycle in a tree."); + throw new QueryException("Cannot add " + item + " to " + this + " as it would create a cycle"); } else if (possibleCycle instanceof CompositeItem) { ensureNotInSubtree((CompositeItem) possibleCycle); } @@ -57,7 +57,7 @@ public abstract class CompositeItem extends Item { } protected void adding(Item item) { - Validator.ensureNotNull("Composite item", item); + Validator.ensureNotNull("A composite item child", item); Validator.ensure("Attempted to add a composite to itself", item != this); if (item instanceof CompositeItem) { ensureNotInSubtree((CompositeItem) item); diff --git a/container-search/src/main/java/com/yahoo/search/querytransform/LowercasingSearcher.java b/container-search/src/main/java/com/yahoo/search/querytransform/LowercasingSearcher.java index 05623570dd4..58486c98dbd 100644 --- a/container-search/src/main/java/com/yahoo/search/querytransform/LowercasingSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/querytransform/LowercasingSearcher.java @@ -9,11 +9,9 @@ import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; import java.util.ArrayList; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import static com.yahoo.language.LinguisticsCase.toLowerCase; diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java index 70896bbad5f..931ee99fdaa 100644 --- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java @@ -14,6 +14,7 @@ import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; import com.yahoo.prelude.query.AndItem; +import com.yahoo.prelude.query.CompositeItem; import com.yahoo.prelude.query.Highlight; import com.yahoo.prelude.query.IndexedItem; import com.yahoo.prelude.query.Item; @@ -726,6 +727,46 @@ public class QueryTestCase { "text:headline", "text:content", "text:description", "text:default", "nontext:tags", "nontext:sddocname", "nontext:embargo", "nontext:expires"); } + @Test + public void testCompositeChildVerification() { + CompositeItem root = new AndItem(); + try { + root.addItem(null); + fail("Expected exception"); + } + catch (NullPointerException e) { + assertEquals("A composite item child can not be null", e.getMessage()); + } + + try { + root.addItem(root); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("Attempted to add a composite to itself", e.getMessage()); + } + + try { + OrItem child = new OrItem(); + child.addItem(root); + root.addItem(child); + fail("Expected exception"); + } + catch (QueryException e) { + assertEquals("Cannot add OR (AND ) to (AND ) as it would create a cycle", e.getMessage()); + } + + try { + OrItem child = new OrItem(); + root.addItem(child); + child.addItem(root); + fail("Expected exception"); + } + catch (QueryException e) { + assertEquals("Cannot add (AND (OR )) to (OR ) as it would create a cycle", e.getMessage()); + } + } + private void assertDetectionText(String expectedDetectionText, String queryString, String ... indexSpecs) { Query q = new Query(httpEncode("/?query=" + queryString)); IndexFacts indexFacts = new IndexFacts(); |