tiled icon indicating copy to clipboard operation
tiled copied to clipboard

queries.Contains cannot find entries when searching from a tree instance

Open canismarko opened this issue 1 month ago • 1 comments

When I search in a non-HTTP client created from a tree instance, the Contains query return an empty set, where if I run the same search using Eq, then I get the correctly filtered entries.

Description

I'm following the documentation for creating a client from a (service-side) tree instance, except using tiled.examples.generated instead of minimal example.

Two of the entries have "color": "red" in their metadata. I should be able to find these.

The following works as expected and returns these two entries:

client.search(Eq("color", "red"))

Expected Result

I expect the follow query to result in the same result as Eq, since "red" does contain "red". This is the result I get if I try to use Contains with a catalog-backed HTTP Tiled server.

results = client.search(Contains("color", "red"))

Actual Result

The following queries are empty.

results = client.search(Contains("color", "red"))
results = client.search(Contains("color", "re"))

Tested with Tiled 0.1.0b7, Tiled 0.1.0b10, and Tiled 0.1.0b13.

Context

We use a non-HTTP client for running our unit tests. The code under test is working correctly when used with a full Tiled server backed by a catalog, but the test-suit fails because the Contains query in the COT is not returning the results we expect.

Previously, we didn't notice because we used a Regex query instead. With the move to Catalog based storage for Bluesky, we've switched to use the Contains query until the regex support is available.

Minimum Working Example

from tiled.client import Context, from_context
from tiled.examples.generated import tree
from tiled.queries import Contains, Eq
from tiled.server.app import build_app

app = build_app(tree)
context = Context.from_app(app)
client = from_context(context)
# Search using equals
results = client.search(Eq("color", "red"))
assert len(results) > 0, len(results)
# Search using contains
results = client.search(Contains("color", "red"))
assert len(results) > 0, len(results)  # <- fails

results in the following output.

Generating large example data...
Done generating example data.
Tiled version 0.1.0b13
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
File /local/btsync/research-spc/haven_support/test_tiled_contains.py:14
     12 # Search using contains
     13 results = client.search(Contains("color", "red"))
---> 14 assert len(results) > 0, len(results)  # <- fails

AssertionError: 0

canismarko avatar Jan 21 '25 19:01 canismarko