Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.logic.search.inmemory

pack-priv Class BibEntryMatchVisitor

extends SearchBaseVisitor<Boolean>
Class Inheritance
Imports
java.time.Duration, java.util.EnumSet, .List, .Locale, java.util.regex.Pattern, .PatternSyntaxException, org.jabref.logic.search.query.SearchFieldConstants, org.jabref.model.entry.BibEntry, org.jabref.model.entry.field.Field, .StandardField, org.jabref.model.search.SearchFlags, org.jabref.model.search.query.SearchQuery, org.jabref.search.SearchBaseVisitor, .SearchParser, com.github.benmanes.caffeine.cache.Cache, .Caffeine, org.slf4j.Logger, .LoggerFactory

Walks a Search.g4 parse tree against a single BibEntry and returns whether the entry matches.

Operator semantics mirror org.jabref.logic.search.query.SearchToSqlVisitor. Pseudo-fields supported: any / anyfield, key, entrytype, anykeyword.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
private static record

Field Summary

Modifier and TypeField and Description
private static final Cache<BibEntryMatchVisitor.RegexKey, Pattern>
COMPILED_PATTERNS

Compiled regexes shared across all visitor instances (one instance is created per BibEntry, so an instance-level cache would not help when scanning a library).

private final BibEntry
private static final String
private final Character
private static final Logger
private final EnumSet<SearchFlags>

Constructor Summary

AccessConstructor and Description
pack-priv
BibEntryMatchVisitor(BibEntry entry, EnumSet<SearchFlags> searchBarFlags, Character keywordSeparator)

Method Summary

Modifier and TypeMethod and Description
private boolean
private static BibEntryMatchVisitor.OperatorFlags
mapOperator(int tokenType)

private boolean
matchAnyField(String term, SearchFlags matchKind, boolean caseSensitive)

private boolean
matchAnyKeyword(String term, SearchFlags matchKind, boolean caseSensitive)

private boolean
matchField(String fieldName, String term, SearchFlags matchKind, boolean caseSensitive)

private boolean
matchNamedField(String fieldName, String term, SearchFlags matchKind, boolean caseSensitive)

private static boolean
matchRegex(String value, String pattern, boolean caseSensitive)

private static boolean
public Boolean
public Boolean
public Boolean
public Boolean
public Boolean
public Boolean
public Boolean
Inherited from org.jabref.search.SearchBaseVisitor:
visitOperatorvisitSearchValue

Field Detail

COMPILED_PATTERNSback to summary
private static final Cache<BibEntryMatchVisitor.RegexKey, Pattern> COMPILED_PATTERNS

Compiled regexes shared across all visitor instances (one instance is created per BibEntry, so an instance-level cache would not help when scanning a library). Keyed by pattern + case mode.

entryback to summary
private final BibEntry entry
GROUPS_FIELD_NAMEback to summary
private static final String GROUPS_FIELD_NAME
keywordSeparatorback to summary
private final Character keywordSeparator
LOGGERback to summary
private static final Logger LOGGER
searchBarFlagsback to summary
private final EnumSet<SearchFlags> searchBarFlags

Constructor Detail

BibEntryMatchVisitorback to summary
pack-priv BibEntryMatchVisitor(BibEntry entry, EnumSet<SearchFlags> searchBarFlags, Character keywordSeparator)

Method Detail

isFieldPresentback to summary
private boolean isFieldPresent(String fieldName)
mapOperatorback to summary
private static BibEntryMatchVisitor.OperatorFlags mapOperator(int tokenType)
matchAnyFieldback to summary
private boolean matchAnyField(String term, SearchFlags matchKind, boolean caseSensitive)
matchAnyKeywordback to summary
private boolean matchAnyKeyword(String term, SearchFlags matchKind, boolean caseSensitive)
matchFieldback to summary
private boolean matchField(String fieldName, String term, SearchFlags matchKind, boolean caseSensitive)
matchNamedFieldback to summary
private boolean matchNamedField(String fieldName, String term, SearchFlags matchKind, boolean caseSensitive)
matchRegexback to summary
private static boolean matchRegex(String value, String pattern, boolean caseSensitive)
matchValueback to summary
private static boolean matchValue(String value, String term, SearchFlags matchKind, boolean caseSensitive)
Parameters
matchKind:SearchFlags

one of SearchFlags#INEXACT_MATCH, SearchFlags#EXACT_MATCH, SearchFlags#REGULAR_EXPRESSION

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.

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

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.

Annotations
@Override
visitComparisonExpressionback to summary
public Boolean visitComparisonExpression(SearchParser.ComparisonExpressionContext ctx)

Overrides org.jabref.search.SearchBaseVisitor.visitComparisonExpression.

Implements org.jabref.search.SearchVisitor.visitComparisonExpression.

Doc from org.jabref.search.SearchBaseVisitor.visitComparisonExpression.

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

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

Annotations
@Override
visitImplicitAndExpressionback to summary
public Boolean visitImplicitAndExpression(SearchParser.ImplicitAndExpressionContext ctx)

Overrides org.jabref.search.SearchBaseVisitor.visitImplicitAndExpression.

Implements org.jabref.search.SearchVisitor.visitImplicitAndExpression.

Doc from org.jabref.search.SearchBaseVisitor.visitImplicitAndExpression.

Visit a parse tree produced by the implicitAndExpression labeled alternative in SearchParser#andExpression.

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

Annotations
@Override
visitNegatedExpressionback to summary
public Boolean visitNegatedExpression(SearchParser.NegatedExpressionContext ctx)

Overrides org.jabref.search.SearchBaseVisitor.visitNegatedExpression.

Implements org.jabref.search.SearchVisitor.visitNegatedExpression.

Doc from org.jabref.search.SearchBaseVisitor.visitNegatedExpression.

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

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

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.

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.

Annotations
@Override
org.jabref.logic.search.inmemory back to summary

private final Record BibEntryMatchVisitor.OperatorFlags

extends Record
Class Inheritance
Record Components
matchKind:SearchFlags
one of SearchFlags#INEXACT_MATCH, SearchFlags#EXACT_MATCH, SearchFlags#REGULAR_EXPRESSION
caseSensitive:boolean 
negation:boolean 

Field Summary

Modifier and TypeField and Description
private final boolean
caseSensitive

Record Component accessed by caseSensitive().

private final SearchFlags
private final boolean
negation

Record Component accessed by negation().

Constructor Summary

AccessConstructor and Description
private
OperatorFlags(SearchFlags matchKind, boolean caseSensitive, boolean negation)

Method Summary

Modifier and TypeMethod and Description
public boolean
caseSensitive()

Record Component getter of caseSensitive.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public SearchFlags
public boolean
negation()

Record Component getter of negation.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

caseSensitiveback to summary
private final boolean caseSensitive

Record Component accessed by caseSensitive().

matchKindback to summary
private final SearchFlags matchKind

Record Component accessed by matchKind().

one of SearchFlags#INEXACT_MATCH, SearchFlags#EXACT_MATCH, SearchFlags#REGULAR_EXPRESSION

negationback to summary
private final boolean negation

Record Component accessed by negation().

Constructor Detail

OperatorFlagsback to summary
private OperatorFlags(SearchFlags matchKind, boolean caseSensitive, boolean negation)

Method Detail

caseSensitiveback to summary
public boolean caseSensitive()

Record Component getter of caseSensitive.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

matchKindback to summary
public SearchFlags matchKind()

Record Component getter of matchKind.

Record Component
one of SearchFlags#INEXACT_MATCH, SearchFlags#EXACT_MATCH, SearchFlags#REGULAR_EXPRESSION
negationback to summary
public boolean negation()

Record Component getter of negation.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

org.jabref.logic.search.inmemory back to summary

private final Record BibEntryMatchVisitor.RegexKey

extends Record
Class Inheritance
Record Components
pattern:String 
caseSensitive:boolean 

Field Summary

Modifier and TypeField and Description
private final boolean
caseSensitive

Record Component accessed by caseSensitive().

private final String
pattern

Record Component accessed by pattern().

Constructor Summary

AccessConstructor and Description
private
RegexKey(String pattern, boolean caseSensitive)

Method Summary

Modifier and TypeMethod and Description
public boolean
caseSensitive()

Record Component getter of caseSensitive.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public String
pattern()

Record Component getter of pattern.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

caseSensitiveback to summary
private final boolean caseSensitive

Record Component accessed by caseSensitive().

patternback to summary
private final String pattern

Record Component accessed by pattern().

Constructor Detail

RegexKeyback to summary
private RegexKey(String pattern, boolean caseSensitive)

Method Detail

caseSensitiveback to summary
public boolean caseSensitive()

Record Component getter of caseSensitive.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

patternback to summary
public String pattern()

Record Component getter of pattern.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.