Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search: NOT binds more than AND #8241

Merged
merged 3 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/antlr4/org/jabref/search/Search.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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 or title = test
| comparison #atomExpression
;

comparison:
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/jabref/model/groups/SearchGroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}