Skip to main content

Filter and bias

Filters restrict address suggestions to matching addresses. Biases rank matching addresses first but still return the rest. Both are query parameters on findAddress, and the autocomplete helper accepts them alongside query in find.

Filter to an area​

Add a filter, such as postcode_outward, to the query.

filter.tsts
import { createIdpcClient, findAddress } from "@ideal-postcodes/sdk";

const client = createIdpcClient({ apiKey: "ak_test" });
const { data } = await findAddress({
client,
query: { query: "malyons road", postcode_outward: "BR8" },
});
console.log(data.result.hits);

With the autocomplete helper, pass the same parameter to find:

filter-autocomplete.tsts
const hits = await autocomplete.find({ query: "high street", country: "Wales" });

An invalid filter term returns an empty list.

Bias towards an area​

Add a bias, such as bias_post_town. Addresses outside the post town still appear, ranked lower.

bias.tsts
const { data } = await findAddress({
client,
query: { query: "high street", bias_post_town: "Edinburgh" },
});

To favour addresses near a point, pass bias_lonlat as longitude, latitude and radius in metres. To favour addresses near the user, set bias_ip to "true". The API uses the approximate location of the IP address that sends the request, so call it from the browser rather than your server.

bias-location.tsts
const near = await autocomplete.find({
query: "high street",
bias_lonlat: "-0.12767,51.503541,5000",
});

An invalid bias term has no effect.

Filters​

FilterRestricts suggestions toExample
postcodeA full postcodeBR8 7RE
postcode_outwardAn outward code, the first half of a postcodeBR8
postcode_areaA postcode area, the leading letters of a postcodeBR
postcode_sectorA postcode sector, the outward code plus the first digit of the inward codeBR8 7
post_townA Royal Mail post town, city or localityLondon
uprnOne UPRN. Takes a number and accepts a single term only50002012147
countryA country: England, Scotland, Wales, Northern Ireland, Jersey, Guernsey or Isle of ManScotland
postcode_typeRoyal Mail postcode user type: S small user, L large userL

country never takes United Kingdom. Pass one of the seven values above.

A small user postcode covers a group of delivery points, 19 on average and never more than 100. A large user postcode belongs to one address, because of the volume of mail it receives or because it has a PO Box or Selectapost service.

Biases​

BiasRanks firstExample
bias_postcodeA full postcodeBR8 7RE
bias_postcode_outwardAn outward codeBR8
bias_post_townA post town, city or localityManchester
bias_lonlatA circle given as longitude,latitude,radius, radius in metres up to 50000-2.095,57.15,100
bias_ipThe approximate location of the requesting IP address. Takes "true" only"true"

Multiple terms​

Separate terms with commas to match any of them, such as postcode_area: "SW,SE". Separate filters combine, so each one narrows the list further.

The API accepts at most 8 filter terms and 5 bias terms per request. uprn takes one term, and bias_lonlat takes one circle.

See findAddress for every parameter and the API reference for the underlying request.