clarin.sru.queryparser¶
- class clarin.sru.queryparser.SRUQuery(raw_query: str, parsed_query: _T)[source]¶
-
Holder class for a parsed query to be returned from a SRUQueryParser.
- property parsed_query: _T¶
Get the parsed query as an abstract syntax tree.
- class clarin.sru.queryparser.SRUQueryParser(*args, **kwds)[source]¶
-
Interface for implementing pluggable query parsers.
Parameterized by ‘abstract syntax tree (object) for parsed queries.’
- abstract supports_version(version: SRUVersion | None) bool [source]¶
Check if query is supported by a specific version of SRU/CQL.
- abstract parse_query(version: SRUVersion, parameters: Dict[str, str], diagnostics: SRUDiagnosticList) SRUQuery[_T] | None [source]¶
Parse a query into an abstract syntax tree.
- Parameters:
version – the SRU version the request was made
parameters – the request parameters containing the query
diagnostics – a SRUDiagnosticList for storing fatal and non-fatal diagnostics
- Returns:
the parsed query or
None
if the query could not be parsed
- class clarin.sru.queryparser.SRUQueryParserRegistry(parsers: List[SRUQueryParser[Any]])[source]¶
Bases:
object
A registry to keep track of registered SRUQueryParser to be used by the SRUServer.
See also
SRUQueryParser
- property query_parsers: List[SRUQueryParser[Any]]¶
Get a list of all registered query parsers.
- Returns:
List[SRUQueryParser[Any]] –
- a list of registered query
parsers
- find_query_parser(query_type: str) SRUQueryParser[Any] | None [source]¶
Find a query parser by query type.
- Parameters:
query_type – the query type to search for
- Returns:
SRUQueryParser[Any] –
- the matching SRUQueryParser
instance or
None
if no matching parser was found.
- class Builder(register_defaults: bool = True)[source]¶
Bases:
object
Builder for creating SRUQueryParserRegistry instances.
[Constructor]
- Parameters:
register_defaults – if
True
, register SRU/CQL standard query parsers (queryType cql and searchTerms), otherwise do nothing. Defaults to True.
- register_defaults() Builder [source]¶
Registers registers SRU/CQL standard query parsers (queryType cql and searchTerms).
- register(parser: SRUQueryParser[Any]) Builder [source]¶
Register a new query parser
- Parameters:
parser (SRUQueryParser[Any]) – the query parser instance to be registered
- Raises:
SRUConfigException – if a query parser for the same query type was already registered
- build() SRUQueryParserRegistry [source]¶
Create a configured SRUQueryParserRegistry instance from this builder.
- Returns:
SRUQueryParserRegistry –
- a SRUQueryParserRegistry
instance
- class clarin.sru.queryparser.SearchTermsQueryParser(*args, **kwds)[source]¶
Bases:
SRUQueryParser
[List
[str
]]- supports_version(version: SRUVersion | None) bool [source]¶
Check if query is supported by a specific version of SRU/CQL.
- parse_query(version: SRUVersion, parameters: Dict[str, str], diagnostics: SRUDiagnosticList) SRUQuery[List[str]] | None [source]¶
Parse a query into an abstract syntax tree.
- Parameters:
version – the SRU version the request was made
parameters – the request parameters containing the query
diagnostics – a SRUDiagnosticList for storing fatal and non-fatal diagnostics
- Returns:
the parsed query or
None
if the query could not be parsed
- class clarin.sru.queryparser.CQLQuery(raw_query: str, parsed_query: _T)[source]¶
Bases:
SRUQuery
[CQLQuery
]
- class clarin.sru.queryparser.CQLQueryParser(*args, **kwds)[source]¶
Bases:
SRUQueryParser
[CQLQuery
]Default query parser to parse CQL.
- supports_version(version: SRUVersion | None) bool [source]¶
Check if query is supported by a specific version of SRU/CQL.
- parse_query(version: SRUVersion, parameters: Dict[str, str], diagnostics: SRUDiagnosticList) SRUQuery[CQLQuery] | None [source]¶
Parse a query into an abstract syntax tree.
- Parameters:
version – the SRU version the request was made
parameters – the request parameters containing the query
diagnostics – a SRUDiagnosticList for storing fatal and non-fatal diagnostics
- Returns:
the parsed query or
None
if the query could not be parsed