Skip to content

Commit

Permalink
Fix indexing on results after aookyying a search query
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaruland committed Oct 23, 2023
1 parent 98dda33 commit 8cf9556
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions tiled/server/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def pagination_links(base_url, route, path_parts, offset, limit, length_hint):
return links


def apply_search(tree, filters, query_registry):
async def apply_search(tree, filters, query_registry):
queries = defaultdict(
dict
) # e.g. {"text": {"text": "dog"}, "lookup": {"key": "..."}}
Expand Down Expand Up @@ -146,10 +146,19 @@ def apply_search(tree, filters, query_registry):
# Two non-equal KeyLookup queries must return no results.
tree = MapAdapter({})
else:
try:
tree = MapAdapter({key_lookup: tree[key_lookup]}, must_revalidate=False)
except KeyError:
tree = MapAdapter({})
if hasattr(tree, "lookup_adapter"):
entry = await tree.lookup_adapter([key_lookup])
if entry is None:
tree = MapAdapter({})
else:
tree = MapAdapter({key_lookup: entry}, must_revalidate=False)
else:
try:
tree = MapAdapter(
{key_lookup: tree[key_lookup]}, must_revalidate=False
)
except KeyError:
tree = MapAdapter({})

return tree

Expand Down Expand Up @@ -191,7 +200,7 @@ async def construct_entries_response(
max_depth,
):
path_parts = [segment for segment in path.split("/") if segment]
tree = apply_search(tree, filters, query_registry)
tree = await apply_search(tree, filters, query_registry)
tree = apply_sort(tree, sort)

count = await len_or_approx(tree)
Expand Down
2 changes: 1 addition & 1 deletion tiled/server/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async def distinct(
**filters,
):
if hasattr(entry, "get_distinct"):
filtered = apply_search(entry, filters, query_registry)
filtered = await apply_search(entry, filters, query_registry)
distinct = await ensure_awaitable(
filtered.get_distinct, metadata, structure_families, specs, counts
)
Expand Down

0 comments on commit 8cf9556

Please sign in to comment.