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

Fix hidden resource filter in catalog [sc-11549] #2828

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions nucliadb/src/nucliadb/search/search/query_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,15 @@ def _parse_reranker(self) -> Reranker:


def parse_catalog(kbid: str, item: search_models.CatalogRequest) -> CatalogQuery:
if item.hidden:
hidden_filter = Filter(all=[LABEL_HIDDEN])
else:
hidden_filter = Filter(none=[LABEL_HIDDEN])
label_filters: dict[str, Any] = convert_to_node_filters(item.filters + [hidden_filter]) # type: ignore
filters: list[Union[str, Filter]] = item.filters

if item.hidden is not None:
if item.hidden:
filters.append(Filter(all=[LABEL_HIDDEN])) # type: ignore
else:
filters.append(Filter(none=[LABEL_HIDDEN])) # type: ignore

label_filters: dict[str, Any] = convert_to_node_filters(item.filters)
if len(label_filters) > 0:
label_filters = translate_label_filters(label_filters)

Expand Down
13 changes: 13 additions & 0 deletions nucliadb/tests/nucliadb/integration/search/test_hidden.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ async def test_hidden_search(
assert resp.status_code == 200
assert set([r["rid"] for r in resp.json()["paragraphs"]["results"]]) == {r1, r2}

# Test catalog ternary filter
resp = await nucliadb_reader.get(f"/kb/{knowledgebox}/catalog")
assert resp.status_code == 200
assert resp.json()["resources"].keys() == {r1, r2}

resp = await nucliadb_reader.get(f"/kb/{knowledgebox}/catalog?hidden=true")
assert resp.status_code == 200
assert resp.json()["resources"].keys() == {r1}

resp = await nucliadb_reader.get(f"/kb/{knowledgebox}/catalog?hidden=false")
assert resp.status_code == 200
assert resp.json()["resources"].keys() == {r2}


@pytest.fixture()
async def app_context(natsd, storage, nucliadb):
Expand Down
Loading