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

Faceted browse against a JSON list of tags #359

Closed
2 tasks done
simonw opened this issue Aug 12, 2018 · 6 comments
Closed
2 tasks done

Faceted browse against a JSON list of tags #359

simonw opened this issue Aug 12, 2018 · 6 comments
Labels

Comments

@simonw
Copy link
Owner

@simonw simonw commented Aug 12, 2018

If a table has a ["foo", "bar", "baz"] JSON column allow that to be faceted against.

  • Support ?column__arraycontains=x filter queries
  • Support ?_facet_array=column faceting
@simonw
Copy link
Owner Author

@simonw simonw commented Aug 12, 2018

Example table: https://latest-code.datasette.io/code/definitions

Here's a query that does facet counting against that column:

https://latest-code.datasette.io/code-a26fa3c?sql=select+count%28*%29+as+n%2C+j.value+from+definitions+join+json_each%28params%29+j+group+by+j.value+order+by+n+desc%3B

select count(*) as n, j.value
from definitions join json_each(params) j
group by j.value order by n desc;

@simonw
Copy link
Owner Author

@simonw simonw commented Aug 12, 2018

And here's the query for pulling back every record tagged with a specific tag:

https://latest-code.datasette.io/code-a26fa3c?sql=select+*+from+definitions+where+rowid+in+%28%0D%0A++select+definitions.rowid%0D%0A++from+definitions+join+json_each%28params%29+j%0D%0A++where+j.value+%3D+%3Atag%0D%0A%29&tag=filename

select * from definitions where rowid in (
  select definitions.rowid
  from definitions join json_each(params) j
  where j.value = :tag
)

@simonw
Copy link
Owner Author

@simonw simonw commented Aug 12, 2018

Note that there doesn't seem to be a way to use indexes (even indexes on expressions) to speed these up, so this will only ever be effective on smaller data sets, probably in the 10,000-100,000 range. Datasette is often used with smaller data sets so this is still worth pursuing.

@simonw
Copy link
Owner Author

@simonw simonw commented Apr 10, 2019

I'm going to go with ?_facet_array=definitions as the querystring argument for this.

And ?definitions_arraycontains=foo as the filter argument.

simonw added a commit that referenced this issue Apr 10, 2019
Part one of supporting facet-by-JSON-array, refs #359
@simonw
Copy link
Owner Author

@simonw simonw commented Apr 11, 2019

Challenge: facets can also be defined in metadata.json like this:

{
  "databases": {
    "sf-trees": {
      "tables": {
        "Street_Tree_List": {
          "facets": ["qLegalStatus"]
        }
      }
    }
  }
}

But... ?_facet_array=definitions doesn't fit in that data structure. Need to have an alternative mechanism for defining this kind of facet.

@simonw
Copy link
Owner Author

@simonw simonw commented May 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant