mirror of
https://github.com/simonw/datasette.git
synced 2026-09-16 21:44:07 +02:00
parent
b09976b924
commit
ee5b5728bc
3 changed files with 13 additions and 23 deletions
|
|
@ -7,7 +7,7 @@ Datasette facets can be used to add a faceted browse interface to any database t
|
|||
With facets, tables are displayed along with a summary showing the most common values in specified columns.
|
||||
These values can be selected to further filter the table.
|
||||
|
||||
Here's `an example <https://congress-legislators.datasettes.com/legislators/legislator_terms?_facet=type&_facet=party&_facet=state&_facet_size=10>`__:
|
||||
Here's `an example <https://datasette.io/legislators/legislator_terms?_facet=type&_facet=party&_facet=state&_facet_size=10>`__:
|
||||
|
||||
.. image:: https://raw.githubusercontent.com/simonw/datasette-screenshots/0.62/non-retina/faceting-details.png
|
||||
:alt: Screenshot showing facets against a table of congressional legislators. Suggested facets include state_rank and start and end dates, and the displayed facets are state, party and type. Each facet lists values along with a count of rows for each value.
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ The table page and table view API
|
|||
|
||||
Table views that support full-text search can be queried using the ``?_search=TERMS`` query string parameter. This will run the search against content from all of the columns that have been included in the index.
|
||||
|
||||
Try this example: `fara.datasettes.com/fara/FARA_All_ShortForms?_search=manafort <https://fara.datasettes.com/fara/FARA_All_ShortForms?_search=manafort>`__
|
||||
Try `searching Datasette ecosystem repositories for "csv" <https://datasette.io/content/repos?_search=csv>`__ to find tools for working with CSV files.
|
||||
|
||||
SQLite full-text search supports wildcards. This means you can easily implement prefix auto-complete by including an asterisk at the end of the search term - for example::
|
||||
|
||||
|
|
@ -120,41 +120,31 @@ Searches using custom SQL
|
|||
|
||||
You can include full-text search results in custom SQL queries. The general pattern with SQLite search is to run the search as a sub-select that returns rowid values, then include those rowids in another part of the query.
|
||||
|
||||
You can see the syntax for a basic search by running that search on a table page and then clicking "View and edit SQL" to see the underlying SQL. For example, consider this search for `manafort is the US FARA database <https://fara.datasettes.com/fara/FARA_All_ShortForms?_search=manafort>`_::
|
||||
You can see the syntax for a basic search by running that search on a table page and then clicking "View and edit SQL" to see the underlying SQL. For example, consider this search for `repositories mentioning "csv" <https://datasette.io/content/repos?_search=csv>`_::
|
||||
|
||||
/fara/FARA_All_ShortForms?_search=manafort
|
||||
/content/repos?_search=csv
|
||||
|
||||
If you click `View and edit SQL <https://fara.datasettes.com/fara?sql=select%0D%0A++rowid%2C%0D%0A++Short_Form_Termination_Date%2C%0D%0A++Short_Form_Date%2C%0D%0A++Short_Form_Last_Name%2C%0D%0A++Short_Form_First_Name%2C%0D%0A++Registration_Number%2C%0D%0A++Registration_Date%2C%0D%0A++Registrant_Name%2C%0D%0A++Address_1%2C%0D%0A++Address_2%2C%0D%0A++City%2C%0D%0A++State%2C%0D%0A++Zip%0D%0Afrom%0D%0A++FARA_All_ShortForms%0D%0Awhere%0D%0A++rowid+in+%28%0D%0A++++select%0D%0A++++++rowid%0D%0A++++from%0D%0A++++++FARA_All_ShortForms_fts%0D%0A++++where%0D%0A++++++FARA_All_ShortForms_fts+match+escape_fts%28%3Asearch%29%0D%0A++%29%0D%0Aorder+by%0D%0A++rowid%0D%0Alimit%0D%0A++101&search=manafort>`_ you'll see that the underlying SQL looks like this:
|
||||
The generated SQL selects all columns in the table. This simplified version selects just the repository ID, full name and description, using the same full-text search condition. `Run this query <https://datasette.io/content?sql=select%0A++id%2C%0A++full_name%2C%0A++description%0Afrom%0A++repos%0Awhere%0A++rowid+in+%28%0A++++select%0A++++++rowid%0A++++from%0A++++++repos_fts%0A++++where%0A++++++repos_fts+match+escape_fts%28%3Asearch%29%0A++%29%0Aorder+by%0A++id%0Alimit%0A++101&search=csv>`_ with ``search`` set to ``csv``:
|
||||
|
||||
.. code-block:: sql
|
||||
|
||||
select
|
||||
rowid,
|
||||
Short_Form_Termination_Date,
|
||||
Short_Form_Date,
|
||||
Short_Form_Last_Name,
|
||||
Short_Form_First_Name,
|
||||
Registration_Number,
|
||||
Registration_Date,
|
||||
Registrant_Name,
|
||||
Address_1,
|
||||
Address_2,
|
||||
City,
|
||||
State,
|
||||
Zip
|
||||
id,
|
||||
full_name,
|
||||
description
|
||||
from
|
||||
FARA_All_ShortForms
|
||||
repos
|
||||
where
|
||||
rowid in (
|
||||
select
|
||||
rowid
|
||||
from
|
||||
FARA_All_ShortForms_fts
|
||||
repos_fts
|
||||
where
|
||||
FARA_All_ShortForms_fts match escape_fts(:search)
|
||||
repos_fts match escape_fts(:search)
|
||||
)
|
||||
order by
|
||||
rowid
|
||||
id
|
||||
limit
|
||||
101
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ Shows the version of Datasette, Python and SQLite. `Versions example <https://la
|
|||
/-/plugins
|
||||
----------
|
||||
|
||||
Shows a list of currently installed plugins and their versions. `Plugins example <https://san-francisco.datasettes.com/-/plugins>`_:
|
||||
Shows a list of currently installed plugins and their versions. `Plugins example <https://datasette.io/-/plugins>`_:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue