Class SuggestService
This service provides real-time autocomplete suggestions for addresses, streets, cities, and POIs. It's designed for typeahead search experiences.
Key Features:
- Street suggestions: Autocomplete street names with house number availability
- City suggestions: Find cities/localities by partial name
- POI suggestions: Search points of interest with category filtering
- Geocoding: Convert suggestions to precise coordinates
SuggestService service = new SuggestService(config);
// 1. Basic address autocomplete
List<SuggestResult> results = service.search(SuggestOptions.builder()
.text("Provença 5")
.build());
// 2. Filter by country and type
List<SuggestResult> streets = service.search(SuggestOptions.builder()
.text("Gran Via")
.countryCode("ESP")
.geoType(SuggestGeoType.STREET)
.build());
// 3. Geocode a specific result to get coordinates
if (!results.isEmpty()) {
SuggestResult best = results.get(0);
SuggestGeocodeResult coords = service.geocode(SuggestGeocodeOptions.builder()
.cityCode(best.getCity().getCode())
.streetCode(best.getStreet().getCode())
.streetNumber("5")
.build());
}
- See Also:
-
Field Summary
Fields inherited from class com.cercalia.sdk.CercaliaClient
config, httpClient, logger, objectMapper -
Constructor Summary
ConstructorsConstructorDescriptionSuggestService(@NotNull CercaliaConfig config) Creates a new SuggestService with the specified configuration. -
Method Summary
Modifier and TypeMethodDescription@Nullable SuggestGeocodeResultfindAndGeocode(@NotNull String text, @Nullable String countryCode, @Nullable String streetNumber) Combined search and geocode - finds and geocodes the best match.@NotNull CompletableFuture<SuggestGeocodeResult>findAndGeocodeAsync(@NotNull String text, @Nullable String countryCode, @Nullable String streetNumber) Combined search and geocode asynchronously.@NotNull SuggestGeocodeResultgeocode(@NotNull SuggestGeocodeOptions options) Geocode a suggestion to get precise coordinates.@NotNull CompletableFuture<SuggestGeocodeResult>geocodeAsync(@NotNull SuggestGeocodeOptions options) Geocode a suggestion asynchronously.@NotNull List<SuggestResult>search(@NotNull SuggestOptions options) Search for address/POI suggestions based on partial text input.@NotNull CompletableFuture<List<SuggestResult>>searchAsync(@NotNull SuggestOptions options) Search for address/POI suggestions asynchronously.@NotNull List<SuggestResult>searchCities(@NotNull String text, @Nullable String countryCode) Search for city/locality suggestions only.@NotNull CompletableFuture<List<SuggestResult>>searchCitiesAsync(@NotNull String text, @Nullable String countryCode) Search for city/locality suggestions asynchronously.@NotNull List<SuggestResult>searchPois(@NotNull String text, @Nullable String countryCode, @Nullable Coordinate center, @Nullable Integer radius, @Nullable List<String> poiCategories) Search for POI suggestions only.@NotNull CompletableFuture<List<SuggestResult>>searchPoisAsync(@NotNull String text, @Nullable String countryCode, @Nullable Coordinate center, @Nullable Integer radius, @Nullable List<String> poiCategories) Search for POI suggestions asynchronously.@NotNull List<SuggestResult>searchStreets(@NotNull String text, @Nullable String countryCode) Search for street suggestions only.@NotNull CompletableFuture<List<SuggestResult>>searchStreetsAsync(@NotNull String text, @Nullable String countryCode) Search for street suggestions asynchronously.Methods inherited from class com.cercalia.sdk.CercaliaClient
addIfPresent, addIfPresent, addIfPresent, addIfTrue, getConfig, newParams, newParams, request, request, requestAsync, requestAsync
-
Constructor Details
-
SuggestService
Creates a new SuggestService with the specified configuration.- Parameters:
config- the Cercalia configuration
-
-
Method Details
-
search
Search for address/POI suggestions based on partial text input.Use this method for autocomplete/typeahead functionality. Returns suggestions ordered by relevance. Minimum 3 characters recommended for best results.
- Parameters:
options- search configuration- Returns:
- list of suggestions ordered by relevance
- Throws:
CercaliaException- if the request fails
-
searchAsync
@NotNull public @NotNull CompletableFuture<List<SuggestResult>> searchAsync(@NotNull @NotNull SuggestOptions options) Search for address/POI suggestions asynchronously.- Parameters:
options- search configuration- Returns:
- a CompletableFuture with the list of suggestions
-
searchStreets
@NotNull public @NotNull List<SuggestResult> searchStreets(@NotNull @NotNull String text, @Nullable @Nullable String countryCode) Search for street suggestions only.Convenience method for street-only autocomplete.
- Parameters:
text- search textcountryCode- optional country code filter- Returns:
- list of street suggestions
- Throws:
CercaliaException- if the request fails
-
searchStreetsAsync
@NotNull public @NotNull CompletableFuture<List<SuggestResult>> searchStreetsAsync(@NotNull @NotNull String text, @Nullable @Nullable String countryCode) Search for street suggestions asynchronously.- Parameters:
text- search textcountryCode- optional country code filter- Returns:
- a CompletableFuture with the list of street suggestions
-
searchCities
@NotNull public @NotNull List<SuggestResult> searchCities(@NotNull @NotNull String text, @Nullable @Nullable String countryCode) Search for city/locality suggestions only.Convenience method for city-only autocomplete.
- Parameters:
text- search textcountryCode- optional country code filter- Returns:
- list of city suggestions
- Throws:
CercaliaException- if the request fails
-
searchCitiesAsync
@NotNull public @NotNull CompletableFuture<List<SuggestResult>> searchCitiesAsync(@NotNull @NotNull String text, @Nullable @Nullable String countryCode) Search for city/locality suggestions asynchronously.- Parameters:
text- search textcountryCode- optional country code filter- Returns:
- a CompletableFuture with the list of city suggestions
-
searchPois
@NotNull public @NotNull List<SuggestResult> searchPois(@NotNull @NotNull String text, @Nullable @Nullable String countryCode, @Nullable @Nullable Coordinate center, @Nullable @Nullable Integer radius, @Nullable @Nullable List<String> poiCategories) Search for POI suggestions only.Convenience method for POI-only autocomplete.
- Parameters:
text- search textcountryCode- optional country code filtercenter- optional center point for proximity searchradius- optional radius in meterspoiCategories- optional POI category codes- Returns:
- list of POI suggestions
- Throws:
CercaliaException- if the request fails
-
searchPoisAsync
@NotNull public @NotNull CompletableFuture<List<SuggestResult>> searchPoisAsync(@NotNull @NotNull String text, @Nullable @Nullable String countryCode, @Nullable @Nullable Coordinate center, @Nullable @Nullable Integer radius, @Nullable @Nullable List<String> poiCategories) Search for POI suggestions asynchronously.- Parameters:
text- search textcountryCode- optional country code filtercenter- optional center point for proximity searchradius- optional radius in meterspoiCategories- optional POI category codes- Returns:
- a CompletableFuture with the list of POI suggestions
-
geocode
@NotNull public @NotNull SuggestGeocodeResult geocode(@NotNull @NotNull SuggestGeocodeOptions options) Geocode a suggestion to get precise coordinates.After selecting a suggestion from
search(SuggestOptions), use this method to get the exact coordinates for the address. For streets, you can specify a house number to get the precise location.- Parameters:
options- geocode options with codes from suggestion- Returns:
- geocoded result with coordinates and full address
- Throws:
CercaliaException- if geocoding fails or no results found
-
geocodeAsync
@NotNull public @NotNull CompletableFuture<SuggestGeocodeResult> geocodeAsync(@NotNull @NotNull SuggestGeocodeOptions options) Geocode a suggestion asynchronously.- Parameters:
options- geocode options with codes from suggestion- Returns:
- a CompletableFuture with the geocoded result
-
findAndGeocode
@Nullable public @Nullable SuggestGeocodeResult findAndGeocode(@NotNull @NotNull String text, @Nullable @Nullable String countryCode, @Nullable @Nullable String streetNumber) Combined search and geocode - finds and geocodes the best match.This is a convenience method that combines search and geocode in one call. Useful when you need coordinates directly from a text query.
- Parameters:
text- address text to searchcountryCode- optional country code filterstreetNumber- optional street number for geocoding- Returns:
- geocoded result of the best match, or null if no results
- Throws:
CercaliaException- if the request fails
-
findAndGeocodeAsync
@NotNull public @NotNull CompletableFuture<SuggestGeocodeResult> findAndGeocodeAsync(@NotNull @NotNull String text, @Nullable @Nullable String countryCode, @Nullable @Nullable String streetNumber) Combined search and geocode asynchronously.- Parameters:
text- address text to searchcountryCode- optional country code filterstreetNumber- optional street number for geocoding- Returns:
- a CompletableFuture with the geocoded result, or null if no results
-