liara.query
¶
Module Contents¶
Classes¶
Base class for query selection filters. |
|
Filter items which contain a specific metadata field and optionally check if that field matches the provided value. |
|
Filter items by a specific tag, this expects a metadata field named
|
|
Filter items by a provided pattern. The pattern is matched against the path. If it matches, the item will be ignored. |
|
Filter items based on the node kind. Use exclude to invert. |
|
Base class for query sorters. |
|
Sort nodes by metadata. |
|
A query modifies a list of nodes, by sorting and filtering entries. |
API¶
- class liara.query.SelectionFilter¶
Bases:
abc.ABC
Base class for query selection filters.
- abstract match(node: liara.nodes.Node) bool ¶
Return
True
if the node should be kept, elseFalse
.
- class liara.query.MetadataFilter(name, value=None)¶
Bases:
liara.query.SelectionFilter
Filter items which contain a specific metadata field and optionally check if that field matches the provided value.
Initialization
- match(node: liara.nodes.Node) bool ¶
- class liara.query.TagFilter(name)¶
Bases:
liara.query.SelectionFilter
Filter items by a specific tag, this expects a metadata field named
tags
to be present, and that field must support checks for containment usingin
.Initialization
- match(node: liara.nodes.Node) bool ¶
- class liara.query.ExcludeFilter(pattern)¶
Bases:
liara.query.SelectionFilter
Filter items by a provided pattern. The pattern is matched against the path. If it matches, the item will be ignored.
Initialization
- match(node: liara.nodes.Node) bool ¶
- class liara.query.NodeKindFilter(kinds, *, exclude=False)¶
Bases:
liara.query.SelectionFilter
Filter items based on the node kind. Use exclude to invert.
Added in version 2.4.
Initialization
- match(node: liara.nodes.Node) bool ¶
- class liara.query.Sorter(reverse=False)¶
Bases:
abc.ABC
Base class for query sorters.
Initialization
- abstract get_key(item: liara.nodes.Node)¶
Return the key to be used for sorting.
- property reverse: bool¶
Returns
True
if the sort order should be reversed.
- class liara.query.MetadataSorter(item: str, reverse=False, case_sensitive=False)¶
Bases:
liara.query.Sorter
Sort nodes by metadata.
Initialization
- get_key(item: liara.nodes.Node)¶
- class liara.query.Query(nodes: Iterable[liara.nodes.Node])¶
Bases:
typing.Iterable
[typing.Union
[liara.nodes.Node
,liara.template.Page
]]A query modifies a list of nodes, by sorting and filtering entries.
Sorting requires the sort key to be present on all nodes that are to be sorted, otherwise an error is raised. Nodes without a particular key can be filtered out using
with_metadata()
.Index and document nodes will be wrapped in a
Page
instance. Everything else will be returned as aNode
.Initialization
Create a query object for the list of specified nodes.
- limit(limit: int) liara.query.Query ¶
Limit this query to return at most
limit
results.
- with_metadata(name, value=None) liara.query.Query ¶
Limit this query to only include nodes which contain the specific metadata field.
- Parameters:
value – If
value
is provided, the field must exist and match the provided value.
- with_tag(name) liara.query.Query ¶
Limit this query to only include nodes with a metadata field named
tags
which contains the specified tag name.
- exclude(pattern) liara.query.Query ¶
Exclude nodes matching the provided regex pattern. The pattern will be applied to the full path.
Note
This means that a pattern of
a
for example will match a path likebar
, asa
is found insidebar
. If you want to match the specific regular expression and not allow for matches within, use^/a$
.
- without_node_kinds(*args) liara.query.Query ¶
Excludes nodes of a specific type. Multiple kinds can be passed in.
Added in version 2.4.
- with_node_kinds(*args) liara.query.Query ¶
Includes nodes of a specific type. Multiple kinds can be passed in.
Added in version 2.4.
- sorted_by_title(*, reverse=False) liara.query.Query ¶
Sort the entries in this query by the metadata field
title
.
- sorted_by_date(*, reverse=False) liara.query.Query ¶
Sort the entries in this query by the metadata field
date
.
- sorted_by_metadata(tag: str, *, reverse=False, case_sensitive=False) liara.query.Query ¶
Sort the entries in this query by the specified metadata field.
- reversed() liara.query.Query ¶
Return the results of this query in reversed order.