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.ABCBase class for query selection filters.
- abstractmethod match(node: liara.nodes.Node) bool¶
Return
Trueif the node should be kept, elseFalse.
- class liara.query.MetadataFilter(name, value=None)¶
Bases:
liara.query.SelectionFilterFilter 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.SelectionFilterFilter items by a specific tag, this expects a metadata field named
tagsto 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.SelectionFilterFilter 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.SelectionFilterFilter 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.ABCBase class for query sorters.
Initialization
- abstractmethod get_key(item: liara.nodes.Node) Any¶
Return the key to be used for sorting.
- property reverse: bool¶
Returns
Trueif the sort order should be reversed.
- class liara.query.MetadataSorter(item: str, reverse=False, case_sensitive=False)¶
Bases:
liara.query.SorterSort 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
Pageinstance. 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
limitresults.
- with_metadata(name, value=None) liara.query.Query¶
Limit this query to only include nodes which contain the specific metadata field.
- Parameters:
value – If
valueis 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
tagswhich 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
afor example will match a path likebar, asais 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.