Searching CKAN
From CKAN
Contents |
Searching CKAN Datasets
NB: example links here are to http://thedatahub.org/ but this documentation applies to any CKAN instance
You can search datasets in a CKAN instance via:
- The Web Interface: see below
- The API: see http://readthedocs.org/docs/ckan/en/latest/api.html
- SPARQL: see e.g. http://semantic.ckan.net/ and RDF Docs (NB: you need to rdfized the data and load it in a triple-store!)
Here we only document option 1.
Getting Started
To do a search via the web interface you use the search form available on the home page or on the dataset search page
Standard Full-Text Search
The search system performs a full-text search of most of the dataset fields. e.g.:
- name
- title
- notes
- tags (i.e. searching for datasets with a tag that matches the search term)
In addition to returning matching datasets the search also returns a list of tags that match. This can be useful for refining the search of looking at datasets tagged with a particular tag.
Structured Search
In addition you can also search on any specific attribute by prefixing with the attribute name, for example, searching for:
title:chemistry
Will only find datasets which have chemistry in their title.
More usefully:
tags:chemistry
Will only find datasets which have the tag chemistry.
You can combine structured searches with standard, unstructured, full-text search:
chemistry tags:ocean
Will find datasets matching full-text search on chemistry AND having tag ocean.
Full Solr/Lucene Search
For CKAN instances running against a solr search backend (please check with your CKAN admin, but it is the default for CKAN >= 1.5) you can use the full range of Solr syntax - cf http://wiki.apache.org/solr/SolrQuerySyntax.
For example, to search for datasets that do not have a specific value:
-field:[* TO *]
(The range query is a way to express "any value").
Examples
The best way to demonstrate the search is to give some examples:
- search: "chemistry" - datasets matching a full-text search on name, title, notes field plus those tagged with chemistry
- search: "tags:chemistry tags:ocean" - datasets tagged with chemistry AND ocean
- search: "groups:chemistry" - datasets in group chemistry
- search: "chemistry title:blue" - datasets matching on standard full-text search for chemistry AND with 'blue' in the title
- latest datasets modified in the lodcloud group (requires CKAN version at least 1.5.1):
curl http://thedatahub.org/api/action/package_search -d '{"q": "groups:lodcloud", "sort": "metadata_modified desc"}'