Queries

Built in query types

These can be used in searches, as in

c.search(FullText("hello"))

tiled.queries.Comparison(operator, key, value)

Query binary comparison between given key's value to the specified value.

tiled.queries.Contains(key, value)

Query where a given key's value contains the specified value.

tiled.queries.Eq(key, value)

Query equality of a given key's value to the specified value.

tiled.queries.NotEq(key, value)

Query inequality of a given key's value to the specified value.

tiled.queries.FullText(text[, case_sensitive])

Search the full text of all metadata values for word matches.

tiled.queries.In(key, value)

Query if a given key's value is present in the specified list of values.

tiled.queries.NotIn(key, value)

Query if a given key's value is not present in the specified list of values.

tiled.queries.Regex(key, pattern[, ...])

Match a key's value to a regular expression.

Query expressions

The Key object can be used to construct queries in a readable way using standard Python comparison operators, as in

Key("color") == "red"
Key("shape") != "circle"
Key("temperature") > 300

used in searches like

c.search(Key("color") == "red").search(Key("shape") != "circle").search(Key("temperature") > 300)

Notice that, to compound searches, you may use repeated calls to .search() as in

c.search(...).search(...).search(...)

Warning

You cannot use queries with the Python keywords not, and, or or.

In Python, and and or have a particular behavior:

>>> 3 or 5
3

>>> 3 and 5
5

which would result in the first or last query being used, respectively, ignoring all others. This is an unavoidable consequence of Python semantics. Likewise, not X must return True or False; it cannot return a query.

To avoid confusion, Tiled raises a TypeError if you attempt to use a query with not, and, or or.

tiled.queries.Key(key)

Compare a key in the metadata to a value using standard Python operators.