Wimmera CMA Search API

Search API for looking up addresses and roads within the catchment. The api can search for both address and road, or either. This dataset is updated weekly from VicMap Roads and Addresses, sourced via www.data.vic.gov.au.

# Use

The Search API uses a data.gov.au datastore and allows a user to take full advantage of full test search functionality.

An sql attribute is passed to the URL to define the query against the API. Please note that the attribute must be URL encoded. The sql statement takes for form as below:

```
SELECT distinct display, x, y
FROM "4bf30358-6dc6-412c-91ee-a6f15aaee62a"
WHERE _full_text @@ to_tsquery(replace('[term]', ' ', ' %26 '))
LIMIT 10
```

The above will select the top 10 results from the API matching the input 'term', and return the display name as well as an x and y coordinate. 

The full URL for the above query would be:

```
https://data.gov.au/api/3/action/datastore_search_sql?sql=SELECT display, x, y FROM "4bf30358-6dc6-412c-91ee-a6f15aaee62a" WHERE _full_text @@ to_tsquery(replace('[term]', ' ', ' %26 ')) LIMIT 10)
```

# Fields
Any field in the source dataset can be returned via the API. Display, x and y are used in the example above, but any other field can be returned by altering the select component of the sql statement. See examples below.

# Filters
Search data sources and LGA can also be used to filter results. When not using a filter, the API defaults to using all records. See examples below.

## Source Dataset
A filter can be applied to select for a particular source dataset using the 'src' field. The currently available datasets are as follows:

 - **1** for Roads
 - **2** for Address
 - **3** for Localities
 - **4** for Parcels (CREF and SPI)
 - **5** for Localities (Propnum)

## Local Government Area
Filters can be applied to select for a specific local government area using the 'lga_code' field. LGA codes are derrived from Vicmap LGA datasets. Wimmeras LGAs include:

 - **332** Horsham Rural City Council
 - **330** Hindmarsh Shire Council
 - **357** Northern Grampians Shire Council
 - **371** West Wimmera Shire Council
 - **378** Yarriambiack Shire Council

# Examples
**Search for the top 10 addresses and roads with the word 'darlot' in their names:**

```
SELECT distinct display, x, y FROM "4bf30358-6dc6-412c-91ee-a6f15aaee62a" WHERE _full_text @@ to_tsquery(replace('darlot', ' ', ' & ')) LIMIT 10)
```
[example](https://data.gov.au/api/3/action/datastore_search_sql?sql=SELECT%20distinct%20display,%20x,%20y%20FROM%20%224bf30358-6dc6-412c-91ee-a6f15aaee62a%22%20WHERE%20_full_text%20@@%20to_tsquery\(replace\(%27darlot%27,%20%27%20%27,%20%27%20%26%20%27\)\)%20LIMIT%2010)

**Search for all roads with the word 'perkins' in their names:**

```
SELECT distinct display, x, y FROM "4bf30358-6dc6-412c-91ee-a6f15aaee62a" WHERE _full_text @@ to_tsquery(replace('perkins', ' ', ' %26 ')) AND src=1
```
[example](https://data.gov.au/api/3/action/datastore_search_sql?sql=SELECT%20distinct%20display,%20x,%20y%20FROM%20%224bf30358-6dc6-412c-91ee-a6f15aaee62a%22%20WHERE%20_full_text%20@@%20to_tsquery\(replacE\(%27perkins%27,%20%27%20%27,%20%27%20%26%20%27\)\)%20AND%20src=1)

**Search for all addresses with the word 'kalimna' in their names, within Horsham Rural City Council:**

```
SELECT distinct display, x, y FROM "4bf30358-6dc6-412c-91ee-a6f15aaee62a" WHERE _full_text @@ to_tsquery(replace('kalimna', ' ', ' %26 ')) AND src=2 and lga_code=332
```
[example](https://data.gov.au/api/3/action/datastore_search_sql?sql=SELECT%20distinct%20display,%20x,%20y%20FROM%20%224bf30358-6dc6-412c-91ee-a6f15aaee62a%22%20WHERE%20_full_text%20@@%20to_tsquery\(replace\(%27kalimna%27,%20%27%20%27,%20%27%20%26%20%27\)\)%20AND%20src=2%20and%20lga_code=332)

**Search for the top 10 addresses and roads with the word 'green' in their names, returning just their display name, locality, x and y:**

```
SELECT distinct display, locality, x, y FROM "4bf30358-6dc6-412c-91ee-a6f15aaee62a" WHERE _full_text @@ to_tsquery(replace('green', ' ', ' %26 ')) LIMIT 10
```
[example](https://data.gov.au/api/3/action/datastore_search_sql?sql=SELECT%20distinct%20display,%20locality,%20x,%20y%20FROM%20%224bf30358-6dc6-412c-91ee-a6f15aaee62a%22%20WHERE%20_full_text%20@@%20to_tsquery\(replace\(%27green%27,%20%27%20%27,%20%27%20%26%20%27\)\)%20LIMIT%2010)

**Search all addresses in Hindmarsh Shire:**

```
SELECT distinct display, locality, x, y FROM "4bf30358-6dc6-412c-91ee-a6f15aaee62a" WHERE lga_code=330
```
[example](https://data.gov.au/api/3/action/datastore_search_sql?sql=SELECT%20distinct%20display,%20locality,%20x,%20y%20FROM%20%224bf30358-6dc6-412c-91ee-a6f15aaee62a%22%20WHERE%20lga_code=330)

Tags: api, road, search
Organization: Wimmera CMA