OfflineSearchEngine (API Reference)
Class OfflineSearchEngine
- All Implemented Interfaces:
SearchInterface
The OfflineSearchEngine works without internet and unlocks the search and geocoding capabilities of HERE services to provide developers with unmatched flexibility to create differentiating location-enabled applications.
It provides the same interfaces as the SearchEngine, but the results may slightly differ as the results are taken from already downloaded map data instead of initiating a new request to a HERE backend service. This way the data may be, for example, older compared to the data you may receive when using the SearchEngine. On the other hand, this class provides results faster as no online connection is necessary.
In comparison to the SearchEngine, there are a few limitations:
- The IDs of POIs are different and may differ among different map versions.
- The implementation is different and the resources are limited, so the results can differ.
- OfflineSearchEngine sometimes doesn't return the requested number of results.
Note: You can search only within persistent map data (downloaded via MapDownloader) or existing cached data.
However, cached data may be incomplete, which can result in searches returning partial or incomplete information.
Therefore, it is recommended to use persistent map data.
Make sure that at least LayerConfiguration.Feature.OFFLINE_SEARCH is enabled.
For EV rich attributes also enable LayerConfiguration.Feature.EV,
for truck rich attributes also enable LayerConfiguration.Feature.TRUCK_SERVICE_ATTRIBUTES,
for fuel station rich attributes also enable LayerConfiguration.Feature.FUEL_STATION_ATTRIBUTES
in SDKOptions.layerConfiguration.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of this class.OfflineSearchEngine(SDKNativeEngine sdkEngine) Creates a new instance of this class. -
Method Summary
Modifier and TypeMethodDescriptionattach(MyPlaces dataSource, OnTaskCompleted callback) Attach data source into SearchEngine instance.search(StructuredQuery query, SearchOptions options, SearchCallback callback) Performs an asynchronous request to search for places.searchByAddress(AddressQuery query, SearchOptions options, SearchCallback callback) Performs an asynchronous address query search forPlaceinstances.searchByCategory(CategoryQuery query, SearchOptions options, SearchCallback callback) Performs an asynchronous category search forPlaceinstances.searchByCoordinates(GeoCoordinates coordinates, SearchOptions options, SearchCallback callback) Performs an asynchronous search forPlaceinstances based on the given geographic coordinates.searchByPickedPlace(PickedPlace pickedPlace, LanguageCode languageCode, PlaceIdSearchCallback callback) Performs an asynchronous search for aPlacebased on the content found inPickedPlace.searchByPlaceId(PlaceIdQuery query, LanguageCode languageCode, PlaceIdSearchCallback callback) Performs an asynchronous search for aPlacebased on its ID andLanguageCode.searchByText(TextQuery query, SearchOptions options, SearchCallback callback) Performs an asynchronous text query search forPlaceinstances within a givenTextQuery.Area.static OfflineSearchIndex.ErrorsetIndexOptions(SDKNativeEngine sdkEngine, OfflineSearchIndex.Options options, OfflineSearchIndexListener listener) Enables or disables indexing.suggest(StructuredQuery query, SearchOptions options, SuggestCallback callback) Performs an asynchronous request to suggest places for aStructuredQuerybuilt with address elements and returns candidate suggestions sorted by relevance.suggestByText(TextQuery query, SearchOptions options, SuggestCallback callback) Performs an asynchronous request to suggest places for text queries and returns suggestions sorted by relevance.
-
Constructor Details
-
OfflineSearchEngine
Creates a new instance of this class.
- Throws:
InstantiationErrorException-Indicates what went wrong when the instantiation was attempted.
-
OfflineSearchEngine
Creates a new instance of this class.
- Parameters:
sdkEngine-Instance of an existing SDKEngine.
- Throws:
InstantiationErrorException-Indicates what went wrong when the instantiation was attempted.
-
-
Method Details
-
attach
Attach data source into SearchEngine instance. Places from MyPlaces ranked the same way as places from default source. New data source replaces old one. Note: Only OfflineSearchEngine supports search over MyPlaces.
- Parameters:
dataSource-The data source.
callback-The callback to be called when task is completed.
- Returns:
Handle that will be used to manipulate the execution of the task.
-
search
@NonNull public TaskHandle search(@NonNull StructuredQuery query, @NonNull SearchOptions options, @NonNull SearchCallback callback) Performs an asynchronous request to search for places. The user submits a
StructuredQuerythat returns places adhering to the constraints provided inStructuredQuery. For example, when user wants results of type street for a text queryInvalidenstraßeinBerlin, it can be searched by preparingStructuredQueryprovidingStructuredQuery.queryasInvalidenstraße,StructuredQuery.areaCenter,StructuredQuery.AddressElements.countryasGermany,StructuredQuery.AddressElements.cityasBerlinandStructuredQuery.ResultTypeasSTREET. The results will be presented only from the given geographical area.Note: This is a beta release of this feature, so there could be a few bugs and unexpected behaviors. Related APIs may change for new releases without a deprecation process.
- Parameters:
query-Desired structured query to search.
options-Search options.
callback-Callback which receives the result on the main thread.
- Returns:
Handle that will be used to manipulate the execution of the task.
-
suggest
@NonNull public TaskHandle suggest(@NonNull StructuredQuery query, @NonNull SearchOptions options, @NonNull SuggestCallback callback) Performs an asynchronous request to suggest places for a
StructuredQuerybuilt with address elements and returns candidate suggestions sorted by relevance. For example, when user wants suggestions of type street for a text queryInvalidenstraßeinBerlin, it can be searched by preparingStructuredQueryprovidingStructuredQuery.queryasInvalidenstraße,StructuredQuery.areaCenter,StructuredQuery.AddressElements.countryasGermany,StructuredQuery.AddressElements.cityasBerlinandStructuredQuery.ResultTypeasSTREET. The suggestions will be presented only from the given geographical area.Note: This is a beta release of this feature, so there could be a few bugs and unexpected behaviors. Related APIs may change for new releases without a deprecation process.
- Parameters:
query-Desired structured query to search.
options-Search options.
callback-Callback which receives the result on the main thread.
- Returns:
Handle that will be used to manipulate the execution of the task.
-
setIndexOptions
@Nullable public static OfflineSearchIndex.Error setIndexOptions(@NonNull SDKNativeEngine sdkEngine, @NonNull OfflineSearchIndex.Options options, @NonNull OfflineSearchIndexListener listener) Enables or disables indexing. When indexing is enabled, HERE SDK will create a detailed index over persistent map data and update it as needed. A detailed index enables finding data faster and over entire persistent map. Creating an index takes time, but usually no more than a few seconds up to a couple of minutes, depending on persistent map size. As the feature is improved, the indexing time will improve. Also please note that this is a heavy processing task. The stored index increases the space taken by offline maps by around 2-5%. This may also improve in future versions.
Indexing is disabled by default. If you want it enabled, make sure to call setIndexOptions with
OfflineSearchIndex.Options.enabledastruebefore any operations inMapDownloaderorMapUpdaterthat modify the persistent map. Calling setIndexOptions may also create or remove map index to match the previously installed map regions. If the matching index for installed map regions is found, then indexing is skipped. While a new index is being created,OfflineSearchEnginefunctionality can still be used. However, without a valid index in place yet, it operates as though indexing is disabled. IfSDKNativeEngineis disposed during indexing (for example, by closing the app), the indexing is cancelled. RecreatingSDKNativeEngineand enabling indexing will ensure that index is created.Note: This is a beta release of this feature, so there could be a few bugs and unexpected behaviors. Related APIs may change for new releases without a deprecation process.
- Parameters:
sdkEngine-Indexing is enabled and disabled per SDKNativeEngine instance. The index is created inside the related
SDKOptions.persistentMapStoragePath.options-Sets indexing options.
listener-The listener that will receive updates about indexing process. When
OfflineSearchIndex.Options.enabledis true, SDK would store listener and the listener will receive updates about indexing progress every time it is performed. WhenOfflineSearchIndex.Options.enabledis false, SDK would report indexing removal progress to the listener one last time and remove storage of listener.- Returns:
An error in case there was one. It's
nullif the indexing listener could be configured successfully.
-
searchByText
@NonNull public TaskHandle searchByText(@NonNull TextQuery query, @NonNull SearchOptions options, @NonNull SearchCallback callback) Performs an asynchronous text query search for
Placeinstances within a givenTextQuery.Area. The returned places are sorted by relevance.- Specified by:
searchByTextin interfaceSearchInterface- Parameters:
query-Desired free-form text query to search.
options-Search options.
callback-Callback which receives the result on the main thread.
- Returns:
Handle that will be used to manipulate the execution of the task.
-
searchByAddress
@NonNull public TaskHandle searchByAddress(@NonNull AddressQuery query, @NonNull SearchOptions options, @NonNull SearchCallback callback) Performs an asynchronous address query search for
Placeinstances. This is the same type of search as forward geocoding, except that more data is returned than just the geographic coordinates of a given address. Note that an address can belong to more than onePlaceresult, although all found places will share the same geographic coordinates. The returned places are sorted by relevance.- Specified by:
searchByAddressin interfaceSearchInterface- Parameters:
query-Desired free-form address query text to search.
options-Search options.
callback-Callback which receives the result on the main thread.
- Returns:
Handle that will be used to manipulate the execution of the task.
-
searchByCategory
@NonNull public TaskHandle searchByCategory(@NonNull CategoryQuery query, @NonNull SearchOptions options, @NonNull SearchCallback callback) Performs an asynchronous category search for
Placeinstances. A list containing at least onePlaceCategorymust be provided as part of thequery.- Specified by:
searchByCategoryin interfaceSearchInterface- Parameters:
query-Query with list of desired categories.
options-Search options.
callback-Callback which receives the result on the main thread.
- Returns:
Handle that will be used to manipulate the execution of the task.
-
searchByCoordinates
@NonNull public TaskHandle searchByCoordinates(@NonNull GeoCoordinates coordinates, @NonNull SearchOptions options, @NonNull SearchCallback callback) Performs an asynchronous search for
Placeinstances based on the given geographic coordinates. This is the same search type as reverse geocoding, except that more data is returned than just theAddressrelated to the given coordinates. Note that more than onePlacecan be related to the given coordinates. The returned places are sorted by relevance.- Specified by:
searchByCoordinatesin interfaceSearchInterface- Parameters:
coordinates-The coordinates where to search.
options-Search options.
callback-Callback which receives result on the main thread.
- Returns:
Handle that will be used to manipulate execution of the task.
-
searchByPlaceId
@NonNull public TaskHandle searchByPlaceId(@NonNull PlaceIdQuery query, @Nullable LanguageCode languageCode, @NonNull PlaceIdSearchCallback callback) Performs an asynchronous search for a
Placebased on its ID andLanguageCode.- Specified by:
searchByPlaceIdin interfaceSearchInterface- Parameters:
query-The id of place to search.
languageCode-The preferred language for the search results. When unset or unsupported language is chosen, results will be returned in their local language.
callback-Callback which receives the result on the main thread.
- Returns:
Handle that will be used to manipulate the execution of the task.
-
searchByPickedPlace
@NonNull public TaskHandle searchByPickedPlace(@NonNull PickedPlace pickedPlace, @Nullable LanguageCode languageCode, @NonNull PlaceIdSearchCallback callback) Performs an asynchronous search for a
Placebased on the content found inPickedPlace. IfPickedPlacedata is obtained from the offline map, it may happen that the newer version that is used by the online service represented bySearchEngineno longer contains the related POI. In that case,SearchError.NO_RESULTS_FOUNDerror is reported. When that happens, you may try to obtain the POI from the offline map by callingOfflineSearchEngine.searchByPickedPlace, only available for the Navigate license.- Specified by:
searchByPickedPlacein interfaceSearchInterface- Parameters:
pickedPlace-The content picked from map.
languageCode-The preferred language for the search result. When unset or unsupported language is chosen, result will be returned in the local language.
callback-Callback which receives the result on the main thread.
- Returns:
Handle that will be used to manipulate the execution of the task.
-
suggestByText
@NonNull public TaskHandle suggestByText(@NonNull TextQuery query, @NonNull SearchOptions options, @NonNull SuggestCallback callback) Performs an asynchronous request to suggest places for text queries and returns suggestions sorted by relevance.
Note that while
OfflineSearchEngineincludes as many details as are available,SearchEngineincludes only the information that is relevant for autosuggest use cases. Complete details can be obtained by searching withPlaceIdQuery.- Specified by:
suggestByTextin interfaceSearchInterface- Parameters:
query-Desired text query to search.
options-Search options.
callback-Callback which receives the result on the main thread.
- Returns:
Handle that will be used to manipulate the execution of the task.
-