diff --git a/CHANGELOG.md b/CHANGELOG.md index 65524c63..e8512baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ Guide: https://keepachangelog.com/en/1.0.0/ +- [SearchResult] Mark `matchingName` field as deprecated and add note for absence of values in ApiType.searchBox results. +- [SearchEngine] Add documentation and assertion that ApiType.searchBox does _not_ support batch requests. + ## 2.5.1 - [Demo] Add example for forward(query:options:completion:) to Demo app using SwiftUI. diff --git a/Sources/MapboxSearch/InternalAPI/CoreSearchResultProtocol.swift b/Sources/MapboxSearch/InternalAPI/CoreSearchResultProtocol.swift index d489ec10..3a9239cc 100644 --- a/Sources/MapboxSearch/InternalAPI/CoreSearchResultProtocol.swift +++ b/Sources/MapboxSearch/InternalAPI/CoreSearchResultProtocol.swift @@ -21,6 +21,9 @@ protocol CoreSearchResultProtocol { var addressDescription: String? { get } + /// The feature name, as matched by the search algorithm. + /// Not available in ``ApiType/searchBox`` results. + /// - Warning: The field is exposed for compatibility only and should be considered deprecated. var matchingName: String? { get } var centerLocation: CLLocation? { get } diff --git a/Sources/MapboxSearch/PublicAPI/Engine/SearchEngine.swift b/Sources/MapboxSearch/PublicAPI/Engine/SearchEngine.swift index 1984ff27..46a757d1 100644 --- a/Sources/MapboxSearch/PublicAPI/Engine/SearchEngine.swift +++ b/Sources/MapboxSearch/PublicAPI/Engine/SearchEngine.swift @@ -243,6 +243,7 @@ public class SearchEngine: AbstractSearchEngine { } } + // NOTE: SearchBox does not support batch responses. private func processBatchResponse(_ coreResponse: CoreSearchResponseProtocol?) { guard let coreResponse else { eventsManager.reportError(.responseProcessingFailed) @@ -443,9 +444,12 @@ extension SearchEngine { /// All suggestions must originate from the same search request. /// Suggestions with other types will be ignored. You can use `SearchSuggestion.batchResolveSupported` field for /// filtering. + /// SearchBox does _not_ support batch requests. /// - Parameter suggestions: suggestions list to resolve. All suggestions must originate from the same search /// request. public func select(suggestions: [SearchSuggestion]) { + assert(apiType == .geocoding || apiType == .SBS, "Only geocoding and SBS API types support batch results.") + for suggestion in suggestions { let supported = (suggestion as? CoreResponseProvider)?.originalResponse.coreResult.action?.multiRetrievable == true @@ -458,8 +462,6 @@ extension SearchEngine { .compactMap { $0 as? CoreResponseProvider } .filter { $0.originalResponse.coreResult.action?.multiRetrievable == true } - // let coreSearchResults = suggestionsImpls.compactMap { $0.originalResponse.coreResult } - guard suggestionsImpls.isEmpty == false else { return } diff --git a/Sources/MapboxSearch/PublicAPI/FavoriteRecord.swift b/Sources/MapboxSearch/PublicAPI/FavoriteRecord.swift index 85a32741..6aa98cfd 100644 --- a/Sources/MapboxSearch/PublicAPI/FavoriteRecord.swift +++ b/Sources/MapboxSearch/PublicAPI/FavoriteRecord.swift @@ -11,11 +11,9 @@ public struct FavoriteRecord: IndexableRecord, SearchResult, Codable, Equatable /// A unique identifier for the geographic feature public var mapboxId: String? - /** - The feature name, as matched by the search algorithm. - - - Warning: The field is exposed for compatibility only, will be removed soon. - */ + /// The feature name, as matched by the search algorithm. + /// Not available in ``ApiType/searchBox`` results. + /// - Warning: The field is exposed for compatibility only and should be considered deprecated. public var matchingName: String? /// address formatted with medium style. diff --git a/Sources/MapboxSearch/PublicAPI/HistoryRecord.swift b/Sources/MapboxSearch/PublicAPI/HistoryRecord.swift index 461a81c4..bdcce31f 100644 --- a/Sources/MapboxSearch/PublicAPI/HistoryRecord.swift +++ b/Sources/MapboxSearch/PublicAPI/HistoryRecord.swift @@ -33,11 +33,9 @@ public struct HistoryRecord: IndexableRecord, SearchResult, Codable, Hashable { /// A point accuracy metric for the returned address. public let accuracy: SearchResultAccuracy? - /** - The feature name, as matched by the search algorithm. - - - Warning: The field is exposed for compatibility only, will be removed soon. - */ + /// The feature name, as matched by the search algorithm. + /// Not available in ``ApiType/searchBox`` results. + /// - Warning: The field is exposed for compatibility only and should be considered deprecated. public private(set) var matchingName: String? /// Address formatted with medium style diff --git a/Sources/MapboxSearch/PublicAPI/Search Results/SearchResult.swift b/Sources/MapboxSearch/PublicAPI/Search Results/SearchResult.swift index 7e49400c..6b37cdd5 100644 --- a/Sources/MapboxSearch/PublicAPI/Search Results/SearchResult.swift +++ b/Sources/MapboxSearch/PublicAPI/Search Results/SearchResult.swift @@ -28,6 +28,8 @@ public protocol SearchResult { var coordinate: CLLocationCoordinate2D { get } /// The feature name, as matched by the search algorithm. + /// Not available in ``ApiType/searchBox`` results. + /// - Warning: The field is exposed for compatibility only and should be considered deprecated. var matchingName: String? { get } /// Result address. diff --git a/Tests/MapboxSearchIntegrationTests/search-box/SearchBox_CategorySearchEngineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/search-box/SearchBox_CategorySearchEngineIntegrationTests.swift index c1077a7a..58a54abe 100644 --- a/Tests/MapboxSearchIntegrationTests/search-box/SearchBox_CategorySearchEngineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/search-box/SearchBox_CategorySearchEngineIntegrationTests.swift @@ -25,6 +25,8 @@ final class SearchBox_CategorySearchEngineIntegrationTests: MockServerIntegratio switch result { case .success(let searchResults): XCTAssertFalse(searchResults.isEmpty) + let matchingNames = searchResults.compactMap(\.matchingName) + XCTAssertTrue(matchingNames.isEmpty) expectation.fulfill() case .failure: XCTFail("Error not expected") diff --git a/Tests/MapboxSearchIntegrationTests/search-box/SearchBox_SearchEngineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/search-box/SearchBox_SearchEngineIntegrationTests.swift index ae9e0b6f..4c922052 100644 --- a/Tests/MapboxSearchIntegrationTests/search-box/SearchBox_SearchEngineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/search-box/SearchBox_SearchEngineIntegrationTests.swift @@ -143,40 +143,6 @@ class SearchBox_SearchEngineIntegrationTests: MockServerIntegrationTestCase