diff options
author | Jon Bratseth <bratseth@oath.com> | 2021-09-10 11:22:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-10 11:22:57 +0200 |
commit | ce88c8013db53cc9860fff818c2d18cbee601354 (patch) | |
tree | b5a57d2e8df43b00df0c38d8cd9747f2193fbe21 /container-search | |
parent | 66b850a11d6327aec8adf60a9f1328880df65b32 (diff) | |
parent | abea2d0c3b3e42e2dd0e8a0cd41a44caf97198ba (diff) |
Merge pull request #19003 from takamabe/correct_heuristic_for_negativeItem
correct heuristic for -(N)
Diffstat (limited to 'container-search')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/query/parser/AllParser.java | 4 | ||||
-rw-r--r-- | container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/parser/AllParser.java b/container-search/src/main/java/com/yahoo/prelude/query/parser/AllParser.java index 49bdba2c90f..793d394801f 100644 --- a/container-search/src/main/java/com/yahoo/prelude/query/parser/AllParser.java +++ b/container-search/src/main/java/com/yahoo/prelude/query/parser/AllParser.java @@ -112,6 +112,7 @@ public class AllParser extends SimpleParser { protected Item negativeItem() { int position = tokens.getPosition(); Item item = null; + boolean isComposited = false; try { if ( ! tokens.skip(MINUS)) return null; if (tokens.currentIsNoIgnore(SPACE)) return null; @@ -121,6 +122,7 @@ public class AllParser extends SimpleParser { item = compositeItem(); if (item != null) { + isComposited = true; if (item instanceof OrItem) { // Turn into And AndItem and = new AndItem(); @@ -137,9 +139,11 @@ public class AllParser extends SimpleParser { // Heuristic overdrive engaged! // Interpret -N as a positive item matching a negative number (by backtracking out of this) // but not if there is an explicit index (such as -a:b) + // but interpret -(N) as a negative item matching a positive number // but interpret --N as a negative item matching a negative number if (item instanceof IntItem && ((IntItem)item).getIndexName().isEmpty() && + ! isComposited && ! ((IntItem)item).getNumber().startsWith(("-"))) item = null; diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java index cef8ae1751c..8ca711297d3 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java @@ -1970,6 +1970,13 @@ public class ParseTestCase { } @Test + public void testNegativeTermPositiveNumberInParentheses() { + tester.assertParsed("+a -12", "a -(12)", Query.Type.ALL); + tester.assertParsed("+a -(AND 12 15)", "a -(12 15)", Query.Type.ALL); + tester.assertParsed("+a -12 -15", "a -(12) -(15)", Query.Type.ALL); + } + + @Test public void testSingleNegativeNumberLikeTerm() { tester.assertParsed("-12", "-12", Query.Type.ALL); } |