Published
Edited
Feb 7, 2022
2 stars
Insert cell
Insert cell
toc("h1, h2, h3, h4") // alternatively toc("h1, h2, h3, h4") if you wanted to include the title heading
Insert cell
<div style="background-color:#f6a2a0">
# todo and stuff

tidy syntax to use KEY:VALUE instead of field:item

make a search UI in this notebook

fix style so font sizes are better. h1, h2, h3
Insert cell
# API commands
Insert cell
Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/resource_search?query=format:XLSX`

let responce = await d3.json(search)

return responce.result
}

Insert cell
Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/tag_search?query=energy`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/tag_autocomplete?query=energy`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/term_translation_show?terms=school`

let responce = await d3.json(search)

return responce
}
Insert cell
Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/status_show`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/vocabulary_list`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/organization_activity_list?id=creative-new-zealand`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/recently_changed_packages_activity_list`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/activity_detail_list?id=c9d7bd53-7058-4997-843d-2908c8a3507b`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/package_activity_list_html?id=a0a2c8e1-9950-4785-8fe5-89450c7cec47`

let responce = await d3.json(search)

return responce
}
Insert cell
Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/group_activity_list_html?id=education`

let responce = await d3.json(search)

return responce //.result
}
Insert cell

### [organization_activity_list_html(context, data_dict)](https://docs.ckan.org/en/2.7/api/index.html#ckan.logic.action.get.organization_activity_list_html)
Returns (string) a organization’s activity stream as HTML.

The activity stream is rendered as a snippet of HTML meant to be included in an HTML page, i.e. it doesn’t have any HTML header or footer.

**Parameters**: *id* (string) – the *id* or *name* of the organization

Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/organization_activity_list_html?id=creative-new-zealand`

let responce = await d3.json(search)

return responce //.result
}
Insert cell
Insert cell
{ let search = `https://catalogue.data.govt.nz/api/3/action/recently_changed_packages_activity_list_html`

let responce = await d3.json(search)

return responce //.result
}
Insert cell
Insert cell
response = await d3.json('https://catalogue.data.govt.nz/api/3/action/package_search')
Insert cell
response.help
Insert cell
response.success
Insert cell
response.result
Insert cell
response.result.count
Insert cell
response.result.results
Insert cell
response.result.results[0]
Insert cell
response.result.results[0].tags
Insert cell
response.result.results[0].resources
Insert cell
Insert cell

# package_search Parameters.
ckan default help for package_search, ** [ help_show?name=package_search](https://catalogue.data.govt.nz/api/3/action/help_show?name=package_search)**

**The following search parameters are available. **

### q: (string) the query.
> Optional. Default: `*:*` which returns everything.
> **Example:** *q=flood* datasets containing the word 'flood', 'floods' or 'flooding'

---
### fq: (string) [Filter Query Parameter](https://solr.apache.org/guide/6_6/common-query-parameters.html#CommonQueryParameters-Thefq_FilterQuery_Parameter).

**string** is '*key:value*'

The fq parameter can be specified multiple times in a query. Documents will only be included in the result if they are in the intersection of the document sets resulting from each instance of the parameter.

> **Example:** *fq=tags:economy*
datasets with the tag "economy".

In the example below, only documents which have a *metadata_created* between 2017-04-12T00:00:00Z and 2017-06-30T23:59:99.999Z are returned:

> **Example:** *fq=metadata_created:[2017-04-12T00:00:00Z TO 2017-06-30T23:59:99.999Z]&q=energy*

This examples results are for documents issues from 2020-01-12 to present date.
> **Example:** *fq=issued:[2020-01-12 TO &ast;]&q=energy*

Filter queries can involve complicated Boolean queries.

the below example has two conditional filters in the *fq*,
the **+** sets the filter to include documents in the issued date range.
the **-** sets the filter to excluded documents with the *name* electricity-market-information
> **Example:** *fq=**+**issued:[2020-01-12 TO &ast;]**-**name:electricity-market-information&q=energy*

---
### sort: (string) sorting of the search results.
If the sort parameter is omitted, sorting is performed as though the parameter were set to score desc.

Optional. Default: *'relevance asc, metadata_modified desc'*. ????

A comma-separated string of *key* and sort direction: *asc* or *desc* (default)
> space or %20 is the separator between key and direction.

sort=key direction,key%20direction]

> **Example:** *?sort=relevance asc,metadata_modified desc*

---
### rows: (int) the number of matching rows to return.
There is a hard limit of 1000 datasets per query.

---
### start: (int) the offset in the complete result for where the set of returned datasets should begin.

---

## Results:

The result of this action is a dictionary returned with the following keys:

* **count** (int) the number of results found.
Note, this is the total number of results found, not the total number of results returned
(which is affected by limit and row parameters used in the input).

* **results** (list of dictized datasets.) ordered list of datasets matching the query, where the ordering defined by the sort parameter used in the query.


Each entry of the outer dictionary is itself a dictionary, with a "*title*" key, and an "*items*" key.
The "*items*" key's value is a list of dicts, each with "*count*", "*display_name*" and "*name*" entries.
The *display_name* is a form of the name that can be used in titles.


**An example result:**

I don't think that data.govt.nz uses *facets / search_facets*
>> ~~~js
{count: 2,
sort: "score desc, metadata_modified desc",
facets: Object {},
results: Array(2)[ { result }, { result }],
search_facets: Object {}
}
~~~


Insert cell
sortExample = {
let search = 'https://catalogue.data.govt.nz/api/3/action/package_search?sort=relevance asc,metadata_modified desc'
let responce = await d3.json(search)
return responce.result
}
Insert cell
t0 = {
let search = 'https://catalogue.data.govt.nz/api/3/action/package_search'
let responce = await d3.json(search)
return responce.result
}
Insert cell
t1 = {
let search = 'https://catalogue.data.govt.nz/api/3/action/package_search?fq=+issued:[2020-01-12 TO *]-name:electricity-market-information&q=energy'
let responce = await d3.json(search)
return responce.result
}
Insert cell
Insert cell
result = {

let search = 'https://catalogue.data.govt.nz/api/3/action/package_search?q=energy&rows=42&q=manawatu'
let responce = await d3.json(search)
return responce.result
}
Insert cell
Insert cell
{
let dateFrom = new Date('2018-04-12 00:00:00 UTC').toISOString()
let dateToo = new Date('2018-06-30 23:59:59 UTC').toISOString()

let search = `https://catalogue.data.govt.nz/api/3/action/package_search?fq=metadata_created:[${dateFrom} TO ${dateToo}]`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{
let dateFrom = new Date('2018-04-12 00:00:00 UTC').toISOString()
let dateToo = new Date('2018-06-30 23:59:59 UTC').toISOString()

let search = `https://catalogue.data.govt.nz/api/3/action/package_search?q=energy&fq=metadata_created:[${dateFrom} TO ${dateToo}]`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/package_list`

let responce = await d3.json(search)

return responce.result
}

Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/package_show?id=1893-womens-suffrage-petition`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/group_list`
let responce = await d3.json(search)

return responce.result
}

Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/group_show?id=arts-culture-and-heritage`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/tag_list`

let responce = await d3.json(search)

return responce.result
}

Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/tag_show?id=accounting`

let responce = await d3.json(search)

return responce.result
}
Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/tag_show?id=Accounting`

let responce = await d3.json(search)

return responce.result
}
Insert cell
Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/recently_changed_packages_activity_list`

let responce = await d3.json(search)

return responce.result
}
Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/package_search?facet.field=[%22tags%22]&facet.limit=20&rows=20`

let responce = await d3.json(search)

return responce.result
}
Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/package_search?fq=tags:economy`

let responce = await d3.json(search)

return responce.result
}

Insert cell
{
let search = `https://catalogue.data.govt.nz/api/3/action/package_search?fq=author:"Stats NZ"`

let responce = await d3.json(search)

return responce.result
}
Insert cell
import { toc } from "@nebrius/indented-toc"
Insert cell
<style>
* {
font-family: sans-serif;
}

@media (hover: hover) {
.katex-display,p,table,ul,h1,h2,h3,h4
{
max-width: 1100px;
min-width: 1100px;
margin-left:10px;
}
}
</style>

Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more