Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
canismarko opened this issue Jan 21, 2025 · 1 comment

Comments

@canismarko
Copy link
Contributor

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
Copy link
Contributor Author

If I remove this line, then the MWE works. Looks like the filter is not matching if the search term is a string. Not sure why this would be in there?

and (not isinstance(term, str))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant