Autocomplete and fuzzy search
Fuzzy search
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 FuzzySearchQuery
class. To create FuzzySearchQuery
you have to use FuzzySearchQueryBuilder
. The only required parameter for fuzzy search is the query
string parameter. The other parameters are optional.
let builder = FuzzySearchQueryBuilder(query: "Pizza")
To get the best experience, consider:
- Using
builder.with(maxFuzzyLevel:Int)
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. (
builder.with(position: CLLocationCoordinate2D)
) - Using
builder.with(radius: Int)
if geo-biasing is not strong enough to keep your results local to the user. - Using https://developer.tomtom.com/assets/downloads/tomtom-sdks/ios/api-reference/0.2.1455/TomTomSDKSearch/Classes/BaseSearchQueryBuilder.html
builder.with(idxSet: [IndexType)
] 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 FuzzySearchQuery
object, provide it to the TomTomOnlineSearchService
.
1let query = builder.build()2searchService.fuzzySearch(query: query) { searchResponse, error in3 if let searchResponse = searchResponse {4 // handle success5 } else if let error = error {6 // handle error7 }8 // Your code goes here.9}
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
class that can be made using AutocompleteQueryBuilder
. The required parameters are the query
and the language
in which 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 builder = AutocompleteQueryBuilder(query: "Piz", forLanguage: "en-GB")
Once you have an AutocompleteQuery
object, provide it to the TomTomOnlineSearchService
.
1let query = builder.build()2searchService.autocomplete(query: query) { autocompleteResponse, error in3 if let autocompleteResponse = autocompleteResponse {4 // handle success5 } else if let error = error {6 // handle error7 }8 // Your code goes here.9}