Autocomplete and fuzzy search

VERSION 0.2.2822
PUBLIC PREVIEW

Fuzzy search is the default, generic search service. It can handle vague and imprecise inputs and supply results for:

  • Areas on the map (countries, states, cities).
  • Specific addresses with a street name and number (2501 Soquel Drive, Kalverstraat 23).
  • Address ranges on streets where address points are interpolated along the length of the street.
  • Streets.
  • Junctions, places where two streets intersect.
  • Point of interest (Restaurant, Sports Center).

Fuzzy search requests are built using the SearchQuery class. The only required parameter for fuzzy search is the query string parameter. The other parameters are optional.

To get the best experience, consider:

  • Using maxFuzzyLevel to balance between performance and breadth of results. It can also be tuned to reduce unusual results.
  • Using position to perform geo-biasing, which boosts the priority of results relevant to the user’s current location.
  • Using radius if geo-biasing is not strong enough to keep your results local to the user.
  • Using resultTypeSet to limit results to specific categories, e.g., POIs or addresses only.

More information about best practices is described at Best Practices. A detailed description of Fuzzy Search and its parameters can be found in the Search API Fuzzy Search documentation.

Once you have a SearchQuery object, provide it to the OnlineSearch.

1let query = SearchQuery("Pizza")
2onlineSearch.search(query: query) { result in
3 switch result {
4 case let .success(searchResponse):
5 // handle success
6 break
7 case let .failure(error):
8 // handle error
9 break
10 }
11}

Autocomplete

Autocomplete helps users make more effective searches. It recognizes entities inside an input query and offers them as query terms. This improves the accuracy of the search results.

Autocomplete requests are built using the AutocompleteQuery struct. The required parameters are the query and the locale in which the autocomplete results should be returned. You can also provide optional parameters to perform a more accurate search, following similar recommendations as for fuzzy search. Also, see more information in the Search API Autocomplete documentation.

let query = AutocompleteQuery(query: "Piz", locale: Locale(identifier: "en_GB"))

Once you have an AutocompleteQuery object, provide it to the OnlineSearch.

1onlineSearch.autocompleteSearch(query: query) { result in
2 switch result {
3 case let .success(autocompleteReponse):
4 // handle success
5 break
6 case let .failure(error):
7 // handle error
8 break
9 }
10}