From e3feae58042a7a26ed6a5f3492bffe2b9cb2fe8b Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 14 Nov 2021 21:59:28 +0100 Subject: [PATCH 1/3] Add test for NOT --- .../jabref/model/groups/SearchGroupTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/java/org/jabref/model/groups/SearchGroupTest.java b/src/test/java/org/jabref/model/groups/SearchGroupTest.java index c5b2f6a68da..5bdec41d87e 100644 --- a/src/test/java/org/jabref/model/groups/SearchGroupTest.java +++ b/src/test/java/org/jabref/model/groups/SearchGroupTest.java @@ -3,6 +3,7 @@ import java.util.EnumSet; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; import org.jabref.model.search.rules.SearchRules; import org.junit.jupiter.api.Test; @@ -29,4 +30,24 @@ public void containsDoesNotFindsWordWithInvalidRegularExpression() { assertFalse(group.contains(entry)); } + + @Test + public void notQueryWorksWithLeftPartOfQuery() { + SearchGroup groupToBeClassified = new SearchGroup("to-be-classified", GroupHierarchyType.INDEPENDENT, "NOT(groups=alpha) AND NOT(groups=beta)", EnumSet.noneOf(SearchRules.SearchFlags.class)); + + BibEntry alphaEntry = new BibEntry() + .withCitationKey("alpha") + .withField(StandardField.GROUPS, "alpha"); + assertFalse(groupToBeClassified.contains(alphaEntry)); + } + + @Test + public void notQueryWorksWithLRightPartOfQuery() { + SearchGroup groupToBeClassified = new SearchGroup("to-be-classified", GroupHierarchyType.INDEPENDENT, "NOT(groups=alpha) AND NOT(groups=beta)", EnumSet.noneOf(SearchRules.SearchFlags.class)); + + BibEntry betaEntry = new BibEntry() + .withCitationKey("beta") + .withField(StandardField.GROUPS, "beta"); + assertFalse(groupToBeClassified.contains(betaEntry)); + } } From a6de0d0b6f1434f59ad7b0be9fc4a96b2bb71574 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 14 Nov 2021 22:07:30 +0100 Subject: [PATCH 2/3] Fix operator predecence --- src/main/antlr4/org/jabref/search/Search.g4 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/antlr4/org/jabref/search/Search.g4 b/src/main/antlr4/org/jabref/search/Search.g4 index 097083e3366..1d57ad7eaa3 100644 --- a/src/main/antlr4/org/jabref/search/Search.g4 +++ b/src/main/antlr4/org/jabref/search/Search.g4 @@ -34,10 +34,11 @@ start: // labels are used to refer to parts of the rules in the generated code later on // label=actualThingy expression: - LPAREN expression RPAREN #parenExpression // example: (author=miller) - | left=expression operator=(AND | OR) right=expression #binaryExpression // example: author = miller and title = test - | NOT expression #unaryExpression // example: not author = miller - | comparison #atomExpression + LPAREN expression RPAREN #parenExpression // example: (author=miller) + | NOT expression #unaryExpression // example: not author = miller + | left=expression operator=AND right=expression #binaryExpression // example: author = miller and title = test + | left=expression operator=OR right=expression #binaryExpression // example: author = miller and title = test + | comparison #atomExpression ; comparison: From 859a06030f14fb1b16b26274816e0238369f81c9 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 14 Nov 2021 22:31:56 +0100 Subject: [PATCH 3/3] Fix and/or --- src/main/antlr4/org/jabref/search/Search.g4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/antlr4/org/jabref/search/Search.g4 b/src/main/antlr4/org/jabref/search/Search.g4 index 1d57ad7eaa3..e2ee78b6c9d 100644 --- a/src/main/antlr4/org/jabref/search/Search.g4 +++ b/src/main/antlr4/org/jabref/search/Search.g4 @@ -37,7 +37,7 @@ expression: LPAREN expression RPAREN #parenExpression // example: (author=miller) | NOT expression #unaryExpression // example: not author = miller | left=expression operator=AND right=expression #binaryExpression // example: author = miller and title = test - | left=expression operator=OR right=expression #binaryExpression // example: author = miller and title = test + | left=expression operator=OR right=expression #binaryExpression // example: author = miller or title = test | comparison #atomExpression ;