-
Notifications
You must be signed in to change notification settings - Fork 29
Migration guide to version 3.x
Version 3 brought a few incompatible changes to the Android client's public interface. This guide will help you adapt your code to work with the new version.
This guide only focuses on incompatible changes. For a complete list of all changes, please refer to ChangeLog.md
at the root of the repository.
-
The
APIClient
class is now calledClient
. -
If you used to specify the
enableDsn
and/ordsnHost
when constructing anAPIClient
, remove those parameters as they are no longer supported. -
If you used to specify hosts when constructing an
APIClient
:- First consider whether you really need to do so. The default hosts leverage our fault-tolerant DNS and are highly recommended in most use cases.
- If you really need to specify hosts, use an array (
String[]
) instead of a list (List<String>
).
-
Methods have been renamed to use an
Async
suffix (note the lowercase S) instead ofASync
. -
All asynchronous methods now use a new, unique listener called
CompletionHandler
. Its interface contains a single method used for both success and error cases. In addition to simplifying the code and aligning the Android client with other languages, this makes it possible to use Java 8 lambda expressions. You will have to rewrite all your listeners accordingly.
First of all, the Query
class now provides low-level methods to access any parameter (even not implemented yet) in an untyped fashion: use the get(String)
/set(String, String)
methods. You should therefore no longer be blocked by missing parameters.
The class has undergone quite a few changes, with the following goals:
-
Bring it in line with the REST API. This implies renaming parameters, adding missing parameters or (in some rare cases) removing them.
-
Honor the essentially optional nature of all query parameters. A null value is acceptable and is the default for all parameters, including primitive types, which are now represented by the corresponding boxed type (e.g.
Integer
forint
). -
Provide adequate types:
-
For parameters taking a list of strings, arrays (
String[]
) are now used instead of lists (List<String>
), making it possible to leverage variable arguments. -
Enum values have been renamed to better match those in the REST API.
-
-
Consistent naming convention: accessors to parameter
fooBar
are now namedgetFooBar()
andsetFooBar()
.
-
analyticsTags
is now typedString[]
(variable arguments allowed). -
aroundLatitudeLongitude()
has been renamed tosetAroundLatLng()
and is now typedLatLng
. Also, the overloaded flavors accepting a radius and a precision have been removed; use the individual setters instead. -
aroundLatitudeLongitudeViaIP()
has been renamed tosetAroundLatLngViaIP()
. Also, the overloaded flavors accepting a radius and a precision have been removed; use the individual setters instead. -
attributesToHighlight
is now exclusively typedString[]
(variable arguments allowed). -
attributesToRetrieve
is now exclusively typedString[]
(variable arguments allowed). -
attributesToSnippet
is now exclusively typedString[]
(variable arguments allowed). -
enableAvancedSyntax()
has been renamed tosetAdvancedSyntax()
. -
enableAnalytics()
has been renamed tosetAnalytics()
. -
enableDistinct()
has been renamed tosetDistinct()
and is now exclusively typedInteger
. -
enableRemoveStopWords()
has been renamed tosetRemoveStopWords()
. -
enableReplaceSynonymsInHighlight()
has been renamed tosetReplaceSynonymsInHighlight()
. -
enableSynonyms()
has been renamed tosetSynonyms()
. -
enableTyposOnNumericTokens()
has been renamed tosetAllowTyposOnNumericTokens()
. -
enableTypoTolerance()
has been renamed tosetTypoTolerance()
and is now enum-typed. -
getRankingInfo()
has been renamed tosetGetRankingInfo()
. -
ignorePlural()
has been renamed tosetIgnorePlurals()
. -
insideBoundingBox()
has been renamed tosetInsideBoundingBox()
and is now typedGeoRect[]
(variable arguments allowed). -
insidePolygon()
has been renamed tosetInsidePolygon()
and is now typedLatLng[]
(variable arguments allowed). -
removeWordsIfNoResult()
has been renamedsetRemoveWordsIfNoResult()
. -
restrictSearchableAttributes()
has been renamed tosetRestrictSearchableAttributes()
. -
restrictSearchableAttributes
is now typedString[]
(variable arguments allowed). -
setFacets()
is now exclusively typedString[]
(variable arguments allowed). -
setFacetFilters()
is now exclusively typedJSONArray
, using the same JSON notation as the REST API. -
setMaxNumberOfFacets()
has been renamed tosetMaxValuesPerFacet()
. -
setHighlightingTags()
has been removed. Use the individual setters instead. -
setMinWordSizeToAllowOneTypo()
has been renamed tosetMinWordSizefor1Typo()
. -
setMinWordSizeToAllowTwoTypos()
has been renamed tosetMinWordSizefor2Typos()
. -
setNbHitsPerPage()
has been removed. UsesetHitsPerPage()
instead. -
setNumericFilters()
is now typedJSONArray
, using the same JSON notation as the REST API. -
setOptionalWords()
is now exclusively typedString[]
(variable arguments allowed). -
setQueryString()
has been renamed tosetQuery()
. -
setSimilarQueryString()
has been removed. -
setTagFilters()
is now typedJSONArray
, using the same JSON notation as the REST API.
-
Accessors to obsolete security HTTP headers have been removed (
APIClient.setSecurityTags()
,APIClient.setUserToken()
). If you need them:- First please consider migrating to secured API keys, which are now the preferred way to deal with per-user authorization.
- If you really need the legacy headers, you may set them via
Client.setHeaders()
.
-
Operations requiring an admin API key have been removed. For obvious security reasons, the admin key should never be used on the client side. There is no plan to reintegrate those features.
-
@NonNull
annotations are consistently used throughout the API wherever a parameter is mandatory. Please respect them, otherwise your code is likely to crash!