?_facet_size=100 parameter, closes #1332

This commit is contained in:
Simon Willison 2021-05-22 17:34:33 -07:00
commit 9789b94da4
5 changed files with 73 additions and 4 deletions

View file

@ -84,6 +84,8 @@ This works for both the HTML interface and the ``.json`` view. When enabled, fac
If Datasette detects that a column is a foreign key, the ``"label"`` property will be automatically derived from the detected label column on the referenced table.
The default number of facet results returned is 30, controlled by the :ref:`setting_default_facet_size` setting. You can increase this on an individual page by adding ``?_facet_size=100`` to the query string, up to a maximum of :ref:`setting_max_returned_rows` (which defaults to 1000).
Facets in metadata.json
-----------------------

View file

@ -371,6 +371,12 @@ Special table arguments
Pagination by continuation token - pass the token that was returned in the
``"next"`` property by the previous page.
``?_facet=column``
Facet by column. Can be applied multiple times, see :ref:`facets`. Only works on the default JSON output, not on any of the custom shapes.
``?_facet_size=100``
Increase the number of facet results returned for each facet.
``?_trace=1``
Turns on tracing for this page: SQL queries executed during the request will
be gathered and included in the response, either in a new ``"_traces"`` key

View file

@ -619,6 +619,7 @@ Each Facet subclass implements a new type of facet operation. The class should l
# using self.sql and self.params as the starting point
facet_results = {}
facets_timed_out = []
facet_size = self.get_facet_size()
# Do some calculations here...
for column in columns_selected_for_facet:
try: