mirror of
https://github.com/simonw/datasette.git
synced 2026-06-10 19:16:57 +02:00
Add per-table suggest_facets configuration option
Allow disabling suggested facets for individual tables by setting "suggest_facets": false in table configuration. This is useful for tables where facet suggestions are unhelpful or too expensive, while keeping them enabled for other tables in the same instance. https://claude.ai/code/session_01JkWNePDCxMYKcq5qSfMo3r
This commit is contained in:
parent
1c6c6d2e68
commit
1a53bdc793
4 changed files with 86 additions and 1 deletions
|
|
@ -1002,6 +1002,39 @@ def test_suggest_facets_off():
|
|||
)
|
||||
|
||||
|
||||
def test_suggest_facets_off_per_table():
|
||||
with make_app_client(
|
||||
metadata={
|
||||
"databases": {
|
||||
"fixtures": {
|
||||
"tables": {
|
||||
"facetable": {"suggest_facets": False},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
) as client:
|
||||
# suggested_facets should be [] for the table with suggest_facets: false
|
||||
assert (
|
||||
[]
|
||||
== client.get("/fixtures/facetable.json?_extra=suggested_facets").json[
|
||||
"suggested_facets"
|
||||
]
|
||||
)
|
||||
# But other tables should still get suggestions
|
||||
other = client.get(
|
||||
"/fixtures/simple_primary_key.json?_extra=suggested_facets"
|
||||
).json["suggested_facets"]
|
||||
# simple_primary_key has a 'content' column that can be faceted
|
||||
assert isinstance(other, list)
|
||||
# Explicit facets should still work even when suggestions are off
|
||||
response = client.get(
|
||||
"/fixtures/facetable.json?_facet=state&_extra=suggested_facets"
|
||||
)
|
||||
assert response.json["suggested_facets"] == []
|
||||
assert response.json["facet_results"]["results"] != {}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("nofacet", (True, False))
|
||||
async def test_nofacet(ds_client, nofacet):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue