Top Description Inners Fields Constructors Methods
org.jabref.model.search.rules

public Class GrammarBasedSearchRule

extends FullTextSearchRule
Class Inheritance
Annotations
@AllowedToUseLogic:Because access to the lucene index is needed
Imports
java.util.ArrayList, .EnumSet, .List, .Objects, .Optional, .Set, java.util.function.Predicate, java.util.regex.Matcher, .Pattern, java.util.stream.Collectors, org.jabref.architecture.AllowedToUseLogic, org.jabref.model.entry.BibEntry, .Keyword, org.jabref.model.entry.field.Field, .InternalField, org.jabref.model.pdf.search.SearchResult, org.jabref.model.search.rules.SearchRules.SearchFlags, org.jabref.model.strings.StringUtil, org.jabref.search.SearchBaseVisitor, .SearchLexer, .SearchParser, org.antlr.v4.runtime.ANTLRInputStream, .BailErrorStrategy, .BaseErrorListener, .CommonTokenStream, .RecognitionException, .Recognizer, org.antlr.v4.runtime.misc.ParseCancellationException, org.antlr.v4.runtime.tree.ParseTree, org.slf4j.Logger, .LoggerFactory

The search query must be specified in an expression that is acceptable by the Search.g4 grammar.

This class implements the "Advanced Search Mode" described in the help

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public static class
public static enum
public static class

Field Summary

Modifier and TypeField and Description
private static final Logger
private String
private final EnumSet<SearchRules.SearchFlags>
private List<SearchResult>
private ParseTree
Inherited from org.jabref.model.search.rules.FullTextSearchRule:
lastPdfSearchResultslastQuery

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
public String
public EnumSet<SearchRules.SearchFlags>
public ParseTree
private void
init(String query)

public static boolean
public boolean
Inherited from org.jabref.model.search.rules.FullTextSearchRule:
getFulltextResults

Field Detail

LOGGERback to summary
private static final Logger LOGGER

Hides org.jabref.model.search.rules.FullTextSearchRule.LOGGER.

queryback to summary
private String query
searchFlagsback to summary
private final EnumSet<SearchRules.SearchFlags> searchFlags

Hides org.jabref.model.search.rules.FullTextSearchRule.searchFlags.

searchResultsback to summary
private List<SearchResult> searchResults
treeback to summary
private ParseTree tree

Constructor Detail

GrammarBasedSearchRuleback to summary
public GrammarBasedSearchRule(EnumSet<SearchRules.SearchFlags> searchFlags) throws RecognitionException

Method Detail

applyRuleback to summary
public boolean applyRule(String query, BibEntry bibEntry)

Implements org.jabref.model.search.rules.SearchRule.applyRule.

Annotations
@Override
getQueryback to summary
public String getQuery()
getSearchFlagsback to summary
public EnumSet<SearchRules.SearchFlags> getSearchFlags()

Overrides org.jabref.model.search.rules.FullTextSearchRule.getSearchFlags.

getTreeback to summary
public ParseTree getTree()
initback to summary
private void init(String query) throws ParseCancellationException
isValidback to summary
public static boolean isValid(EnumSet<SearchRules.SearchFlags> searchFlags, String query)
validateSearchStringsback to summary
public boolean validateSearchStrings(String query)

Implements org.jabref.model.search.rules.SearchRule.validateSearchStrings.

Annotations
@Override
org.jabref.model.search.rules back to summary

pack-priv Class GrammarBasedSearchRule.BibtexSearchVisitor

extends SearchBaseVisitor<Boolean>
Class Inheritance

Search results in boolean. It may be later on converted to an int.

Field Summary

Modifier and TypeField and Description
private final BibEntry
private final EnumSet<SearchRules.SearchFlags>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
public Boolean
public Boolean
public Boolean
public Boolean
public Boolean
Inherited from org.jabref.search.SearchBaseVisitor:
visitAtomExpressionvisitName

Field Detail

entryback to summary
private final BibEntry entry
searchFlagsback to summary
private final EnumSet<SearchRules.SearchFlags> searchFlags

Constructor Detail

BibtexSearchVisitorback to summary
public BibtexSearchVisitor(EnumSet<SearchRules.SearchFlags> searchFlags, BibEntry bibEntry)

Method Detail

comparisonback to summary
public boolean comparison(String field, GrammarBasedSearchRule.ComparisonOperator operator, String value)
visitBinaryExpressionback to summary
public Boolean visitBinaryExpression(SearchParser.BinaryExpressionContext ctx)

Overrides org.jabref.search.SearchBaseVisitor.visitBinaryExpression.

Implements org.jabref.search.SearchVisitor.visitBinaryExpression.

Doc from org.jabref.search.SearchBaseVisitor.visitBinaryExpression.

Visit a parse tree produced by the binaryExpression labeled alternative in SearchParser#expression.

The default implementation returns the result of calling visitChildren on ctx.

Parameters
ctx:SearchParser.BinaryExpressionContext

Doc from org.jabref.search.SearchVisitor.visitBinaryExpression.

the parse tree

Returns:Boolean

Doc from org.jabref.search.SearchVisitor.visitBinaryExpression.

the visitor result

Annotations
@Override
visitComparisonback to summary
public Boolean visitComparison(SearchParser.ComparisonContext context)

Overrides org.jabref.search.SearchBaseVisitor.visitComparison.

Implements org.jabref.search.SearchVisitor.visitComparison.

Doc from org.jabref.search.SearchBaseVisitor.visitComparison.

Visit a parse tree produced by SearchParser#comparison.

The default implementation returns the result of calling visitChildren on ctx.

Parameters
context:SearchParser.ComparisonContext

Doc from org.jabref.search.SearchVisitor.visitComparison.

the parse tree

Returns:Boolean

Doc from org.jabref.search.SearchVisitor.visitComparison.

the visitor result

Annotations
@Override
visitParenExpressionback to summary
public Boolean visitParenExpression(SearchParser.ParenExpressionContext ctx)

Overrides org.jabref.search.SearchBaseVisitor.visitParenExpression.

Implements org.jabref.search.SearchVisitor.visitParenExpression.

Doc from org.jabref.search.SearchBaseVisitor.visitParenExpression.

Visit a parse tree produced by the parenExpression labeled alternative in SearchParser#expression.

The default implementation returns the result of calling visitChildren on ctx.

Parameters
ctx:SearchParser.ParenExpressionContext

Doc from org.jabref.search.SearchVisitor.visitParenExpression.

the parse tree

Returns:Boolean

Doc from org.jabref.search.SearchVisitor.visitParenExpression.

the visitor result

Annotations
@Override
visitStartback to summary
public Boolean visitStart(SearchParser.StartContext ctx)

Overrides org.jabref.search.SearchBaseVisitor.visitStart.

Implements org.jabref.search.SearchVisitor.visitStart.

Doc from org.jabref.search.SearchBaseVisitor.visitStart.

Visit a parse tree produced by SearchParser#start.

The default implementation returns the result of calling visitChildren on ctx.

Parameters
ctx:SearchParser.StartContext

Doc from org.jabref.search.SearchVisitor.visitStart.

the parse tree

Returns:Boolean

Doc from org.jabref.search.SearchVisitor.visitStart.

the visitor result

Annotations
@Override
visitUnaryExpressionback to summary
public Boolean visitUnaryExpression(SearchParser.UnaryExpressionContext ctx)

Overrides org.jabref.search.SearchBaseVisitor.visitUnaryExpression.

Implements org.jabref.search.SearchVisitor.visitUnaryExpression.

Doc from org.jabref.search.SearchBaseVisitor.visitUnaryExpression.

Visit a parse tree produced by the unaryExpression labeled alternative in SearchParser#expression.

The default implementation returns the result of calling visitChildren on ctx.

Parameters
ctx:SearchParser.UnaryExpressionContext

Doc from org.jabref.search.SearchVisitor.visitUnaryExpression.

the parse tree

Returns:Boolean

Doc from org.jabref.search.SearchVisitor.visitUnaryExpression.

the visitor result

Annotations
@Override
org.jabref.model.search.rules back to summary

public Class GrammarBasedSearchRule.Comparator

extends Object
Class Inheritance
  • java.lang.Object
  • org.jabref.model.search.rules.GrammarBasedSearchRule.Comparator

Field Summary

Modifier and TypeField and Description
private final Pattern
private final GrammarBasedSearchRule.ComparisonOperator
private final Pattern

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
private Predicate<Field>
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fieldPatternback to summary
private final Pattern fieldPattern
operatorback to summary
private final GrammarBasedSearchRule.ComparisonOperator operator
valuePatternback to summary
private final Pattern valuePattern

Constructor Detail

Comparatorback to summary
public Comparator(String field, String value, GrammarBasedSearchRule.ComparisonOperator operator, EnumSet<SearchRules.SearchFlags> searchFlags)

Method Detail

compareback to summary
public boolean compare(BibEntry entry)
matchFieldKeyback to summary
private Predicate<Field> matchFieldKey()
matchFieldValueback to summary
public boolean matchFieldValue(String content)
org.jabref.model.search.rules back to summary

public final Enum GrammarBasedSearchRule.ComparisonOperator

extends Enum<GrammarBasedSearchRule.ComparisonOperator>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final GrammarBasedSearchRule.ComparisonOperator
public static final GrammarBasedSearchRule.ComparisonOperator
public static final GrammarBasedSearchRule.ComparisonOperator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static GrammarBasedSearchRule.ComparisonOperator
build(String value)

public static GrammarBasedSearchRule.ComparisonOperator
public static GrammarBasedSearchRule.ComparisonOperator[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CONTAINSback to summary
public static final GrammarBasedSearchRule.ComparisonOperator CONTAINS
DOES_NOT_CONTAINback to summary
public static final GrammarBasedSearchRule.ComparisonOperator DOES_NOT_CONTAIN
EXACTback to summary
public static final GrammarBasedSearchRule.ComparisonOperator EXACT

Constructor Detail

ComparisonOperatorback to summary
private ComparisonOperator()

Method Detail

buildback to summary
public static GrammarBasedSearchRule.ComparisonOperator build(String value)
valueOfback to summary
public static GrammarBasedSearchRule.ComparisonOperator valueOf(String name)
valuesback to summary
public static GrammarBasedSearchRule.ComparisonOperator[] values()
org.jabref.model.search.rules back to summary

public Class GrammarBasedSearchRule.ThrowingErrorListener

extends BaseErrorListener
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final GrammarBasedSearchRule.ThrowingErrorListener

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
syntaxError(Recognizer<?, ?>
What parser got the error. From this object, you can access the context as well as the input stream.
recognizer
,
Object
The offending token in the input token stream, unless recognizer is a lexer (then it's null). If no viable alternative error, e has token at which we started production for the decision.
offendingSymbol
,
int
The line number in the input where the error occurred.
line
,
int
The character position within that line where the error occurred.
charPositionInLine
,
String
The message to emit.
msg
,
RecognitionException
The exception generated by the parser that led to the reporting of an error. It is null in the case where the parser was able to recover in line without exiting the surrounding rule.
e
)

Overrides org.antlr.v4.runtime.BaseErrorListener.syntaxError.

Implements org.antlr.v4.runtime.ANTLRErrorListener.syntaxError.

Upon syntax error, notify any interested parties.

Inherited from org.antlr.v4.runtime.BaseErrorListener:
reportAmbiguityreportAttemptingFullContextreportContextSensitivity

Field Detail

INSTANCEback to summary
public static final GrammarBasedSearchRule.ThrowingErrorListener INSTANCE

Constructor Detail

ThrowingErrorListenerback to summary
public ThrowingErrorListener()

Method Detail

syntaxErrorback to summary
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) throws ParseCancellationException

Overrides org.antlr.v4.runtime.BaseErrorListener.syntaxError.

Implements org.antlr.v4.runtime.ANTLRErrorListener.syntaxError.

Doc from org.antlr.v4.runtime.ANTLRErrorListener.syntaxError.

Upon syntax error, notify any interested parties. This is not how to recover from errors or compute error messages. ANTLRErrorStrategy specifies how to recover from syntax errors and how to compute error messages. This listener's job is simply to emit a computed message, though it has enough information to create its own message in many cases.

The RecognitionException is non-null for all syntax errors except when we discover mismatched token errors that we can recover from in-line, without returning from the surrounding rule (via the single token insertion and deletion mechanism).

Parameters
recognizer:Recognizer<?, ?>

What parser got the error. From this object, you can access the context as well as the input stream.

offendingSymbol:Object

The offending token in the input token stream, unless recognizer is a lexer (then it's null). If no viable alternative error, e has token at which we started production for the decision.

line:int

The line number in the input where the error occurred.

charPositionInLine:int

The character position within that line where the error occurred.

msg:String

The message to emit.

e:RecognitionException

The exception generated by the parser that led to the reporting of an error. It is null in the case where the parser was able to recover in line without exiting the surrounding rule.

Annotations
@Override