Skip to content

Commit

Permalink
AttributesSets option for Forward Api cherry-pick for 2.6 (#306)
Browse files Browse the repository at this point in the history
* AttributesSets option for Forward Api (#305)

* Attributes sets support for the Forward Api

* Bump version and update changelog

* Bump version and update changelog
  • Loading branch information
DzmitryFomchyn authored Jan 2, 2025
1 parent 7e9c960 commit 088e12f
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 9 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog for the Mapbox Search SDK for Android

## 2.6.4
- New option `ForwardSearchOptions.attributeSets` is available. It allows to request additional metadata attributes besides the basic ones.

### New features

### Mapbox dependencies
- Search Native SDK `2.6.3`
- Common SDK `24.8.0`



## 2.6.3

### New features
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Mapbox Search SDK for Android version 1.0

Mapbox Search Android SDK

Copyright © 2021 - 2024 Mapbox, Inc. All rights reserved.
Copyright © 2021 - 2025 Mapbox, Inc. All rights reserved.

The software and files in this repository (collectively, "Software") are licensed under the Mapbox TOS for use only with the relevant Mapbox product(s) listed at www.mapbox.com/pricing. This license allows developers with a current active Mapbox account to use and modify the authorized portions of the Software as needed for use only with the relevant Mapbox product(s) through their Mapbox account in accordance with the Mapbox TOS. This license terminates automatically if a developer no longer has a Mapbox account in good standing or breaches the Mapbox TOS. For the license terms, please see the Mapbox TOS at https://www.mapbox.com/legal/tos/ which incorporates the Mapbox Product Terms at www.mapbox.com/legal/service-terms. If this Software is a SDK, modifications that change or interfere with marked portions of the code related to billing, accounting, or data collection are not authorized and the SDK sends limited de-identified location and usage data which is used in accordance with the Mapbox TOS. [Updated 2023-03]
---------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion MapboxSearch/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android.enableJetifier=false
kotlin.code.style=official

# SDK version attributes
VERSION_NAME=2.6.3
VERSION_NAME=2.6.4

# Artifact attributes
mapboxArtifactUserOrg=mapbox
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mapbox.search.sample.api

import android.os.Bundle
import com.mapbox.geojson.Point
import com.mapbox.search.ApiType
import com.mapbox.search.AttributeSet
import com.mapbox.search.ForwardSearchOptions
import com.mapbox.search.ResponseInfo
import com.mapbox.search.SearchCallback
Expand Down Expand Up @@ -32,9 +34,21 @@ class ForwardApiKotlinExampleActivity : BaseKotlinExampleActivity() {
}

override fun startExample() {
val options = ForwardSearchOptions.Builder()
.proximity(Point.fromLngLat(-77.03400742663874, 38.904863105693586))
.attributeSets(
listOf(
AttributeSet.BASIC,
AttributeSet.PHOTOS,
AttributeSet.VENUE,
AttributeSet.VISIT,
)
)
.build()

task = searchEngine.forward(
query = "Mapbox DC",
options = ForwardSearchOptions.Builder().build(),
query = "Starbucks",
options = options,
callback = object : SearchCallback {
override fun onResults(results: List<SearchResult>, responseInfo: ResponseInfo) {
logI("SearchApiExample", "Forward request results:", results)
Expand Down
3 changes: 3 additions & 0 deletions MapboxSearch/sdk/api/api-metalava.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ package com.mapbox.search {
}

@kotlinx.parcelize.Parcelize public final class ForwardSearchOptions implements android.os.Parcelable {
method public java.util.List<com.mapbox.search.AttributeSet>? getAttributeSets();
method public com.mapbox.geojson.BoundingBox? getBoundingBox();
method public java.util.List<com.mapbox.search.common.IsoCountryCode>? getCountries();
method public boolean getIgnoreIndexableRecords();
Expand All @@ -119,6 +120,7 @@ package com.mapbox.search {
method public java.util.List<com.mapbox.search.QueryType>? getTypes();
method public java.util.Map<java.lang.String,java.lang.String>? getUnsafeParameters();
method public com.mapbox.search.ForwardSearchOptions.Builder toBuilder();
property public final java.util.List<com.mapbox.search.AttributeSet>? attributeSets;
property public final com.mapbox.geojson.BoundingBox? boundingBox;
property public final java.util.List<com.mapbox.search.common.IsoCountryCode>? countries;
property public final boolean ignoreIndexableRecords;
Expand All @@ -135,6 +137,7 @@ package com.mapbox.search {

public static final class ForwardSearchOptions.Builder {
ctor public ForwardSearchOptions.Builder();
method public com.mapbox.search.ForwardSearchOptions.Builder attributeSets(java.util.List<? extends com.mapbox.search.AttributeSet>? attributeSets);
method public com.mapbox.search.ForwardSearchOptions.Builder boundingBox(com.mapbox.geojson.BoundingBox boundingBox);
method public com.mapbox.search.ForwardSearchOptions build();
method public com.mapbox.search.ForwardSearchOptions.Builder countries(com.mapbox.search.common.IsoCountryCode... countries);
Expand Down
11 changes: 8 additions & 3 deletions MapboxSearch/sdk/api/sdk.api
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ public final class com/mapbox/search/EtaType$Creator : android/os/Parcelable$Cre

public final class com/mapbox/search/ForwardSearchOptions : android/os/Parcelable {
public static final field CREATOR Landroid/os/Parcelable$Creator;
public synthetic fun <init> (Lcom/mapbox/search/common/IsoLanguageCode;Ljava/lang/Integer;Lcom/mapbox/geojson/Point;Lcom/mapbox/geojson/BoundingBox;Ljava/util/List;Ljava/util/List;Lcom/mapbox/search/SearchNavigationOptions;Lcom/mapbox/geojson/Point;Ljava/lang/Integer;Ljava/util/Map;ZLjava/lang/Double;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final synthetic fun copy (Lcom/mapbox/geojson/Point;Lcom/mapbox/geojson/BoundingBox;Ljava/util/List;Lcom/mapbox/search/common/IsoLanguageCode;Ljava/lang/Integer;Ljava/util/List;Ljava/lang/Integer;Lcom/mapbox/geojson/Point;Lcom/mapbox/search/SearchNavigationOptions;Ljava/util/Map;ZLjava/lang/Double;)Lcom/mapbox/search/ForwardSearchOptions;
public static synthetic fun copy$default (Lcom/mapbox/search/ForwardSearchOptions;Lcom/mapbox/geojson/Point;Lcom/mapbox/geojson/BoundingBox;Ljava/util/List;Lcom/mapbox/search/common/IsoLanguageCode;Ljava/lang/Integer;Ljava/util/List;Ljava/lang/Integer;Lcom/mapbox/geojson/Point;Lcom/mapbox/search/SearchNavigationOptions;Ljava/util/Map;ZLjava/lang/Double;ILjava/lang/Object;)Lcom/mapbox/search/ForwardSearchOptions;
public synthetic fun <init> (Lcom/mapbox/search/common/IsoLanguageCode;Ljava/lang/Integer;Lcom/mapbox/geojson/Point;Lcom/mapbox/geojson/BoundingBox;Ljava/util/List;Ljava/util/List;Lcom/mapbox/search/SearchNavigationOptions;Lcom/mapbox/geojson/Point;Ljava/lang/Integer;Ljava/util/Map;ZLjava/lang/Double;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final synthetic fun copy (Lcom/mapbox/geojson/Point;Lcom/mapbox/geojson/BoundingBox;Ljava/util/List;Lcom/mapbox/search/common/IsoLanguageCode;Ljava/lang/Integer;Ljava/util/List;Ljava/lang/Integer;Lcom/mapbox/geojson/Point;Lcom/mapbox/search/SearchNavigationOptions;Ljava/util/Map;ZLjava/lang/Double;Ljava/util/List;)Lcom/mapbox/search/ForwardSearchOptions;
public static synthetic fun copy$default (Lcom/mapbox/search/ForwardSearchOptions;Lcom/mapbox/geojson/Point;Lcom/mapbox/geojson/BoundingBox;Ljava/util/List;Lcom/mapbox/search/common/IsoLanguageCode;Ljava/lang/Integer;Ljava/util/List;Ljava/lang/Integer;Lcom/mapbox/geojson/Point;Lcom/mapbox/search/SearchNavigationOptions;Ljava/util/Map;ZLjava/lang/Double;Ljava/util/List;ILjava/lang/Object;)Lcom/mapbox/search/ForwardSearchOptions;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getAttributeSets ()Ljava/util/List;
public final fun getBoundingBox ()Lcom/mapbox/geojson/BoundingBox;
public final fun getCountries ()Ljava/util/List;
public final fun getIgnoreIndexableRecords ()Z
Expand All @@ -138,12 +140,15 @@ public final class com/mapbox/search/ForwardSearchOptions : android/os/Parcelabl
public final fun getRequestDebounce ()Ljava/lang/Integer;
public final fun getTypes ()Ljava/util/List;
public final fun getUnsafeParameters ()Ljava/util/Map;
public fun hashCode ()I
public final fun toBuilder ()Lcom/mapbox/search/ForwardSearchOptions$Builder;
public fun toString ()Ljava/lang/String;
public fun writeToParcel (Landroid/os/Parcel;I)V
}

public final class com/mapbox/search/ForwardSearchOptions$Builder {
public fun <init> ()V
public final fun attributeSets (Ljava/util/List;)Lcom/mapbox/search/ForwardSearchOptions$Builder;
public final fun boundingBox (Lcom/mapbox/geojson/BoundingBox;)Lcom/mapbox/search/ForwardSearchOptions$Builder;
public final fun build ()Lcom/mapbox/search/ForwardSearchOptions;
public final fun countries (Ljava/util/List;)Lcom/mapbox/search/ForwardSearchOptions$Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.mapbox.search.Reserved.Flags.SEARCH_BOX
import com.mapbox.search.base.core.CoreSearchOptions
import com.mapbox.search.base.defaultLocaleLanguage
import com.mapbox.search.base.utils.extension.mapToCore
import com.mapbox.search.base.utils.extension.safeCompareTo
import com.mapbox.search.common.IsoCountryCode
import com.mapbox.search.common.IsoLanguageCode
import kotlinx.parcelize.Parcelize
Expand Down Expand Up @@ -112,6 +113,11 @@ public class ForwardSearchOptions private constructor(
* Threshold specified in meters.
*/
public val indexableRecordsDistanceThresholdMeters: Double? = null,

/**
* Request additional metadata attributes besides the basic ones.
*/
public val attributeSets: List<AttributeSet>? = null,
) : Parcelable {

init {
Expand Down Expand Up @@ -142,6 +148,7 @@ public class ForwardSearchOptions private constructor(
unsafeParameters: Map<String, String>? = this.unsafeParameters,
ignoreIndexableRecords: Boolean = this.ignoreIndexableRecords,
indexableRecordsDistanceThresholdMeters: Double? = this.indexableRecordsDistanceThresholdMeters,
attributeSets: List<AttributeSet>? = this.attributeSets,
): ForwardSearchOptions {
return ForwardSearchOptions(
proximity = proximity,
Expand All @@ -156,6 +163,7 @@ public class ForwardSearchOptions private constructor(
unsafeParameters = unsafeParameters,
ignoreIndexableRecords = ignoreIndexableRecords,
indexableRecordsDistanceThresholdMeters = indexableRecordsDistanceThresholdMeters,
attributeSets = attributeSets,
)
}

Expand All @@ -169,6 +177,69 @@ public class ForwardSearchOptions private constructor(
/**
* @suppress
*/
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as ForwardSearchOptions

if (language != other.language) return false
if (limit != other.limit) return false
if (proximity != other.proximity) return false
if (boundingBox != other.boundingBox) return false
if (countries != other.countries) return false
if (types != other.types) return false
if (navigationOptions != other.navigationOptions) return false
if (origin != other.origin) return false
if (requestDebounce != other.requestDebounce) return false
if (unsafeParameters != other.unsafeParameters) return false
if (ignoreIndexableRecords != other.ignoreIndexableRecords) return false
if (!indexableRecordsDistanceThresholdMeters.safeCompareTo(other.indexableRecordsDistanceThresholdMeters)) return false
if (attributeSets != other.attributeSets) return false

return true
}

/**
* @suppress
*/
override fun hashCode(): Int {
var result = language?.hashCode() ?: 0
result = 31 * result + (limit ?: 0)
result = 31 * result + (proximity?.hashCode() ?: 0)
result = 31 * result + (boundingBox?.hashCode() ?: 0)
result = 31 * result + (countries?.hashCode() ?: 0)
result = 31 * result + (types?.hashCode() ?: 0)
result = 31 * result + (navigationOptions?.hashCode() ?: 0)
result = 31 * result + (origin?.hashCode() ?: 0)
result = 31 * result + (requestDebounce ?: 0)
result = 31 * result + (unsafeParameters?.hashCode() ?: 0)
result = 31 * result + ignoreIndexableRecords.hashCode()
result = 31 * result + (indexableRecordsDistanceThresholdMeters?.hashCode() ?: 0)
result = 31 * result + (attributeSets?.hashCode() ?: 0)
return result
}

/**
* @suppress
*/
override fun toString(): String {
return "ForwardSearchOptions(" +
"language=$language, " +
"limit=$limit, " +
"proximity=$proximity, " +
"boundingBox=$boundingBox, " +
"countries=$countries, " +
"types=$types, " +
"navigationOptions=$navigationOptions, " +
"origin=$origin, " +
"requestDebounce=$requestDebounce, " +
"unsafeParameters=$unsafeParameters, " +
"ignoreIndexableRecords=$ignoreIndexableRecords, " +
"indexableRecordsDistanceThresholdMeters=$indexableRecordsDistanceThresholdMeters, " +
"attributeSets=$attributeSets" +
")"
}

/**
* Builder for comfortable creation of [ForwardSearchOptions] instance.
Expand All @@ -188,6 +259,7 @@ public class ForwardSearchOptions private constructor(
private var unsafeParameters: Map<String, String>? = null
private var ignoreIndexableRecords: Boolean = false
private var indexableRecordsDistanceThresholdMeters: Double? = null
private var attributeSets: List<AttributeSet>? = null

internal constructor(options: ForwardSearchOptions) : this() {
proximity = options.proximity
Expand All @@ -203,6 +275,7 @@ public class ForwardSearchOptions private constructor(
ignoreIndexableRecords = options.ignoreIndexableRecords
indexableRecordsDistanceThresholdMeters =
options.indexableRecordsDistanceThresholdMeters
attributeSets = options.attributeSets
}

/**
Expand Down Expand Up @@ -324,6 +397,13 @@ public class ForwardSearchOptions private constructor(
this.indexableRecordsDistanceThresholdMeters = threshold
}

/**
* Request additional metadata attributes besides the basic ones.
*/
public fun attributeSets(attributeSets: List<AttributeSet>?): Builder = apply {
this.attributeSets = attributeSets
}

/**
* Create [ForwardSearchOptions] instance from builder data.
*/
Expand All @@ -340,6 +420,7 @@ public class ForwardSearchOptions private constructor(
unsafeParameters = unsafeParameters,
ignoreIndexableRecords = ignoreIndexableRecords,
indexableRecordsDistanceThresholdMeters = indexableRecordsDistanceThresholdMeters,
attributeSets = attributeSets,
)
}
}
Expand All @@ -364,6 +445,5 @@ internal fun ForwardSearchOptions.mapToCore(): CoreSearchOptions = CoreSearchOpt
timeDeviation = null,
addonAPI = unsafeParameters?.let { (it as? HashMap) ?: HashMap(it) },
ensureResultsPerCategory = null,
// TODO should we support attribute sets for the forward geocoding?
attributeSets = null,
attributeSets = attributeSets?.map { it.mapToCore() },
)
Loading

0 comments on commit 088e12f

Please sign in to comment.