Query syntax


The Search API, the search widget and other DigitalNZ search tools share a powerful search syntax borrowed from the Apache Lucene search engine.

You can test your query syntax using DigitalNZ Search. Note that the results from the DigitalNZ Search interface, may vary slightly from the results returned directly via the API as some material can be blocked from the interface, but still available from API.

Full documentation

The DigitalNZ search system uses Apache Lucene syntax, which is fully described in the Apache Lucene Query Parser Syntax documentation.

Lucene syntax is very powerful, and gives you access to numerous features, including fielded search, boolean operators, Google-style operators, nesting and grouping, proximity operators, wildcards, even fuzzy search.

Field Searching

You can search for text in a specific field by entering field:value in your search string, eg category:Images.

  • field searches are case sensitive
  • you must enclose your value in double quotes if it is more than one word, eg rights:"No known copyright restrictions"
  • to find any value in a field, use [* TO *], eg geo_co_ords:[* TO *] to find all geotagged (mapped) records

Fields that can be searched include:

  • id
  • category
  • collection
  • content_partner
  • century
  • decade
  • year
  • creator
  • language
  • placename
  • rights
  • object_license
  • subject
  • geo_co_ords

Note that DigitalNZ generates the year, decade and century values based on any date metadata associated with a record.

Date range indexing

Date indexed fields can be searched using date range syntax. Fields that can be searched using date range indexing include

  • date (any date associated with the item)
  • syndication_date (the date it was added to DigitalNZ)

The default search field

The "text" field is the default search field: if you do not specify a field explicitly, the text field will be searched.

The text field contains a copy of all these fields: title, description, category, content_partner, creator, subject, year, placename, and fulltext.

Examples

Complex queries can be built up using boolean operators (AND, NOT) and with field searches using field:value syntax.

  • Results from 1908: year:1908
  • Results from the 20th century: century:1900-1999
  • Results where the location is Wellington: placename:Wellington
  • Results where the location starts with Wellington: placename:Wellington*
  • Results from Auckland in 1908: placename:Auckland* AND year:1908
  • Results from North Otago Museum: content_partner:"North Otago Museum"
  • Results from Dictionary of New Zealand Biography website: collection:"Dictionary+of+New+Zealand+Biography"
  • Results covered by Crown Copyright: rights:"Crown copyright"
  • Date range searching: date:[1900-01-01T00:00:00Z TO 1903-01-01T00:00:00Z]
  • Last modified results: last_modified_at:[2010-03-13T00:00:00.000Z TO *]
  • And finally, you can search for everything in DigitalNZ by specifying that you want every value from every field: *:*

For example, results for the name 'William' from within the Dictionary of New Zealand Biography website:

http://api.digitalnz.org/records/v1.xml/?search_text=william%20AND%20collection:"Dictionary+of+New+Zealand
+Biography"&api_key=your_api_key 

For example, last modified records from Flickr:

http://api.digitalnz.org/records/v1.xml/?search_text=last_modified_at:[2010-03-13T00:00:00.000Z%20TO%20*]%20AND%20collection:%22Flickr%22&api_key=your_api_key