search_query.constants

Constants for search-query

Classes

Colors()

Colors for CLI printing

ExitCodes()

Exit codes

Fields()

Search fields

LinterMode()

Linter mode

ListToken(value, type, level, position)

Token class

ListTokenTypes(value)

List token types

OperatorNodeTokenTypes(value)

Operator node token types (list queries)

Operators()

PLATFORM(value)

Database identifier

QueryErrorCode(value)

Error codes for the query parser

SearchField(value, *[, position])

SearchField class.

Token(value, type, position)

Token class

TokenTypes(value)

Token types

class search_query.constants.Colors

Bases: object

Colors for CLI printing

BLUE = '\x1b[94m'
END = '\x1b[0m'
GREEN = '\x1b[92m'
GREY = '\x1b[90m'
ORANGE = '\x1b[93m'
RED = '\x1b[91m'
class search_query.constants.ExitCodes

Bases: object

Exit codes

FAIL = 1
SUCCESS = 0
class search_query.constants.Fields

Bases: object

Search fields

ABSTRACT = 'abstract'
ACCESSION_NUMBER = 'accession-nr'
ADDRESS = 'address'
AFFILIATION = 'affiliation'
ALL = 'all-fields'
AUTHOR = 'author'
AUTHOR_IDENTIFIERS = 'author-identifiers'
AUTHOR_KEYWORDS = 'keywords-author'
CITY = 'city'
CONFERENCE = 'conference'
COUNTRY_REGION = 'country-region'
DESCRIPTORS = 'descriptors'
DOI = 'doi'
EDITOR = 'editor'
FILTER = 'sb'
FUNDING_AGENCY = 'funding-agency'
FUNDING_TEXT = 'funding-text'
GRANT_NUMBER = 'grant-nr'
GROUP_AUTHOR = 'group-author'
ISBN = 'isbn'
ISSN = 'issn'
ISSN_ISBN = 'issn-isbn'
JOURNAL = 'journal'
KEYWORDS = 'keywords'
KEYWORDS_PLUS = 'keywords-plus'
LANGUAGE = 'language'
MESH_TERM = 'mesh-term'
ORGANIZATION = 'organization'
ORGANIZATION_ENHANCED = 'organization-enhanced'
PROVINCE_STATE = 'province-state'
PUBLICATION_NAME = 'publication-name'
PUBLICATION_TYPE = 'publication-type'
PUBLISHER = 'publisher'
PUBMED_ID = 'pmid'
RESEARCH_AREA = 'research-area'
SOURCE = 'source'
STREET_ADDRESS = 'street-address'
SUBJECT_TERMS = 'subject-terms'
SUBORGANIZATION = 'suborganization'
TEXT_WORD = 'text-word'
TITLE = 'title'
TOPIC = 'topic'
WEB_OF_SCIENCE_CATEGORY = 'wos-category'
YEAR_PUBLICATION = 'year-publication'
ZIP_POSTAL_CODE = 'zip'
classmethod all() list

Return all fields as a list.

class search_query.constants.LinterMode

Bases: object

Linter mode

NONSTRICT = 'non-strict'
STRICT = 'strict'
class search_query.constants.ListToken(value: str, type: OperatorNodeTokenTypes, level: int, position: Tuple[int, int])

Bases: object

Token class

level: int
position: Tuple[int, int]
type: OperatorNodeTokenTypes
value: str
class search_query.constants.ListTokenTypes(value)

Bases: Enum

List token types

OPERATOR_NODE = 'OPERATOR_NODE'
QUERY_NODE = 'QUERY_NODE'
class search_query.constants.OperatorNodeTokenTypes(value)

Bases: Enum

Operator node token types (list queries)

LIST_ITEM_REFERENCE = 'LIST_ITEM_REFERENCE'
LOGIC_OPERATOR = 'LOGIC_OPERATOR'
UNKNOWN = 'UNKNOWN'
class search_query.constants.Operators

Bases: object

AND = 'AND'
NEAR = 'NEAR'
NOT = 'NOT'
OR = 'OR'
RANGE = 'RANGE'
WITHIN = 'WITHIN'
class search_query.constants.PLATFORM(value)

Bases: Enum

Database identifier

EBSCO = 'ebscohost'
GENERIC = 'generic'
PRE_NOTATION = 'pre_notation'
PUBMED = 'pubmed'
STRUCTURED = 'structured'
WOS = 'wos'
class search_query.constants.QueryErrorCode(value)

Bases: Enum

Error codes for the query parser

BOOLEAN_OPERATOR_READABILITY = (['all'], 'W0009', 'boolean-operator-readability', 'Boolean operator readability', '')
CHARACTER_REPLACEMENT = ([PLATFORM.PUBMED], 'W0010', 'character-replacement', 'Character replacement', '')
DATE_FILTER_IN_SUBQUERY = ([PLATFORM.PUBMED], 'W0011', 'date-filter-in-subquery', 'Date filter in subquery', '')
DOI_FORMAT_INVALID = ([PLATFORM.WOS], 'F2009', 'doi-format-invalid', 'Invalid DOI format.', '')
EMPTY_PARENTHESES = ([PLATFORM.PUBMED], 'F1009', 'empty-parentheses', 'Query contains empty parentheses', '')
IMPLICIT_NEAR_VALUE = ([PLATFORM.WOS], 'W0006', 'implicit-near-value', 'The value of NEAR operator is implicit', '**Typical fix**: The parser automatically sets NEAR values to 15 (default).\n\n**Problematic query**:\n\n.. code-block:: python\n\n    A NEAR B\n\n**Correct query**:\n\n.. code-block:: python\n\n    A NEAR/15 B')
IMPLICIT_OPERATOR = ([PLATFORM.PUBMED], 'W0012', 'implicit-operator', 'Implicit operator', '')
IMPLICIT_PRECEDENCE = (['all', PLATFORM.PUBMED], 'W0007', 'implicit-precedence', 'Operator changed at the same level (explicit parentheses are recommended)', '')
INVALID_CHARACTER = ([PLATFORM.PUBMED], 'E0004', 'invalid-character', 'Search term contains invalid character', '')
INVALID_LIST_REFERENCE = ([PLATFORM.WOS, PLATFORM.PUBMED], 'F3003', 'invalid-list-reference', 'Invalid list reference in list query', '')
INVALID_PROXIMITY_USE = ([PLATFORM.PUBMED, PLATFORM.EBSCO], 'E0005', 'invalid-proximity-use', 'Invalid use of the proximity operator', '')
INVALID_SYNTAX = (['all'], 'F1010', 'invalid-syntax', 'Query contains invalid syntax', '')
INVALID_TOKEN_SEQUENCE = ([PLATFORM.EBSCO], 'F1004', 'invalid-token-sequence', 'The sequence of tokens is invalid.', '')
INVALID_WILDCARD_USE = ([PLATFORM.PUBMED], 'E0006', 'invalid-wildcard-use', 'Invalid use of the wildcard operator *', '')
ISBN_FORMAT_INVALID = ([PLATFORM.WOS], 'F2008', 'isbn-format-invalid', 'Invalid ISBN format.', '')
JOURNAL_FILTER_IN_SUBQUERY = ([PLATFORM.PUBMED], 'W0014', 'journal-filter-in-subquery', 'Journal (or publication name) filter in subquery', '')
MISSING_OPERATOR_NODES = ([PLATFORM.WOS], 'F3002', 'missing-operator-nodes', 'List format query without operator nodes', '')
MISSING_ROOT_NODE = ([PLATFORM.WOS], 'F3001', 'missing-root-node', 'List format query without root node (typically containing operators)', '')
NEAR_DISTANCE_TOO_LARGE = ([PLATFORM.WOS], 'F2007', 'near-distance-too-large', 'NEAR distance is too large (max: 15).', '')
NESTED_QUERY_WITH_SEARCH_FIELD = ([PLATFORM.PUBMED], 'F2013', 'nested-query-with-search-field', 'A Nested query cannot have a search field.', '')
NON_STANDARD_QUOTES = (['all'], 'W0013', 'non-standard-quotes', 'Non-standard quotes', '')
OPERATOR_CAPITALIZATION = (['all'], 'W0005', 'operator-capitalization', 'Operators should be capitalized', '**Typical fix**: Capitalize the operator\n\n\n**Problematic query**:\n\n.. code-block:: python\n\n    a and b or c\n\n**Correct query**:\n\n.. code-block:: python\n\n    a AND b OR c')
QUERY_IN_QUOTES = ([PLATFORM.WOS], 'E0008', 'query-in-quotes', 'The whole Search string is in quotes.', '')
QUERY_STARTS_WITH_PLATFORM_IDENTIFIER = ([PLATFORM.WOS], 'E0007', 'query-starts-with-platform-identifier', 'Query starts with platform identifier', '')
QUERY_STRUCTURE_COMPLEX = (['all'], 'W0004', 'query-structure-unnecessarily-complex', 'Query structure is more complex than necessary', '')
SEARCH_FIELD_CONTRADICTION = (['all'], 'E0002', 'search-field-contradiction', 'Contradictory search fields specified', '')
SEARCH_FIELD_EXTRACTED = (['all'], 'W0002', 'search-field-extracted', 'Recommend explicitly specifying the search field in the string', '')
SEARCH_FIELD_MISSING = (['all'], 'E0001', 'search-field-missing', 'Expected search field is missing', '')
SEARCH_FIELD_REDUNDANT = (['all'], 'W0001', 'search-field-redundant', 'Recommend specifying search field only once in the search string', '')
SEARCH_FIELD_UNSUPPORTED = (['all', PLATFORM.WOS], 'F2011', 'search-field-unsupported', 'Search field is not supported for this database', '')
TOKENIZING_FAILED = (['all'], 'F0001', 'tokenizing-failed', 'Fatal error during tokenization', '')
TOKEN_AMBIGUITY = (['all'], 'W0008', 'token-ambiguity', 'Token ambiguity', '')
TOO_MANY_OPERATORS = ([PLATFORM.WOS], 'F1011', 'too-many-operators', 'Too many operators in the query', '')
TOO_MANY_SEARCH_TERMS = ([PLATFORM.WOS], 'F1012', 'too-many-search-terms', 'Too many search terms in the query', '')
UNBALANCED_PARENTHESES = (['all'], 'F1001', 'unbalanced-parentheses', 'Parentheses are unbalanced in the query', '**Typical fix**: Check the parentheses in the query\n\n**Problematic query**:\n\n.. code-block:: python\n\n    (a AND b OR c\n\n**Correct query**:\n\n.. code-block:: python\n\n    (a AND b) OR c')
UNBALANCED_QUOTES = (['all'], 'F1002', 'unbalanced-quotes', 'Quotes are unbalanced in the query', '')
UNSUPPORTED_PREFIX = ([PLATFORM.PUBMED], 'W0015', 'unsupported-prefix', 'Unsupported prefix in search query', '')
UNSUPPORTED_SUFFIX = ([PLATFORM.PUBMED], 'W0016', 'unsupported-suffix', 'Unsupported suffix in search query', '')
WILDCARD_AFTER_SPECIAL_CHAR = ([PLATFORM.WOS], 'F2005', 'wildcard-after-special-char', 'Wildcard cannot be preceded by special characters.', '')
WILDCARD_IN_YEAR = ([PLATFORM.WOS], 'F2002', 'wildcard-in-year', 'Wildcard characters (*, ?, $) not supported in year search.', '**Typical fix**: Replace with year range.\n\n**Problematic query**:\n\n.. code-block:: python\n\n    A AND year=201*\n\n**Correct query**:\n\n.. code-block:: python\n\n    A AND (year >= 2010 AND year < 2020)')
WILDCARD_LEFT_SHORT_LENGTH = ([PLATFORM.WOS], 'F2004', 'wildcard-left-short-length', 'Left-hand wildcard must be preceded by at least three characters.', '')
WILDCARD_RIGHT_SHORT_LENGTH = ([PLATFORM.WOS], 'F2003', 'wildcard-right-short-length', 'Right-hand wildcard must preceded by at least three characters.', '')
WILDCARD_STANDALONE = ([PLATFORM.WOS], 'F2006', 'wildcard-standalone', 'Wildcard cannot be standalone.', '')
WILDCARD_UNSUPPORTED = ([PLATFORM.WOS], 'F2001', 'wildcard-unsupported', 'Unsupported wildcard in search string.', '')
YEAR_FORMAT_INVALID = ([PLATFORM.WOS], 'F2014', 'year-format-invalid', 'Invalid year format.', '')
YEAR_SPAN_VIOLATION = ([PLATFORM.WOS], 'F2010', 'year-span-violation', 'Year span must be five or less.', '**Typical fix**: The parser automatically sets the year span to 5.\n\n**Problematic query**:\n\n.. code-block:: python\n\n    A AND PY=2000-2020\n\n**Correct query**:\n\n.. code-block:: python\n\n    A AND PY=2015-2020')
YEAR_WITHOUT_SEARCH_TERMS = ([PLATFORM.WOS], 'F2012', 'year-without-search-terms', 'A search for publication years must include at least another search term.', '**Typical fix**: A search for publication years must include at least another search term.\n\n**Problematic query**:\n\n.. code-block:: python\n\n    PY=2000\n\n**Correct query**:\n\n.. code-block:: python\n\n    PY=2000 AND TI=eHealth')
is_error() bool

Check if error is an error

is_fatal() bool

Check if error is fatal

is_warning() bool

Check if error is a warning

class search_query.constants.SearchField(value: str, *, position: Tuple[int, int] | None = None)

Bases: object

SearchField class.

copy() SearchField

Return a copy of the SearchField instance.

class search_query.constants.Token(value: str, type: TokenTypes, position: Tuple[int, int])

Bases: object

Token class

is_operator() bool

Check if token is an operator

position: Tuple[int, int]
type: TokenTypes
value: str
class search_query.constants.TokenTypes(value)

Bases: Enum

Token types

FIELD = 'FIELD'
LOGIC_OPERATOR = 'LOGIC_OPERATOR'
PARENTHESIS_CLOSED = 'PARENTHESIS_CLOSED'
PARENTHESIS_OPEN = 'PARENTHESIS_OPEN'
PROXIMITY_OPERATOR = 'PROXIMITY_OPERATOR'
RANGE_OPERATOR = 'RANGE_OPERATOR'
SEARCH_TERM = 'SEARCH_TERM'
UNKNOWN = 'UNKNOWN'