Skip to content

Commit 325c117

Browse files
algolia-botmillotp
andcommitted
fix(clients): correctly deserialize SearchResult (#4756) (generated) [skip ci]
Co-authored-by: Pierre Millot <[email protected]>
1 parent 4570f18 commit 325c117

File tree

17 files changed

+68
-21
lines changed

17 files changed

+68
-21
lines changed

clients/algoliasearch-client-csharp/algoliasearch/Clients/SearchClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ public partial interface ISearchClient
16401640
UpdatedAtResponse SaveSynonyms(string indexName, List<SynonymHit> synonymHit, bool? forwardToReplicas = default, bool? replaceExistingSynonyms = default, RequestOptions options = null, CancellationToken cancellationToken = default);
16411641

16421642
/// <summary>
1643-
/// Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
1643+
/// Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
16441644
/// </summary>
16451645
///
16461646
/// Required API Key ACLs:
@@ -1655,7 +1655,7 @@ public partial interface ISearchClient
16551655
Task<SearchResponses<T>> SearchAsync<T>(SearchMethodParams searchMethodParams, RequestOptions options = null, CancellationToken cancellationToken = default);
16561656

16571657
/// <summary>
1658-
/// Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. (Synchronous version)
1658+
/// Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want. (Synchronous version)
16591659
/// </summary>
16601660
///
16611661
/// Required API Key ACLs:

clients/algoliasearch-client-dart/packages/algoliasearch/lib/src/api/search_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ final class SearchClient implements ApiClient {
111111
);
112112
}
113113

114-
/// Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
114+
/// Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
115115
///
116116
/// Required API Key ACLs:
117117
/// - search

clients/algoliasearch-client-dart/packages/client_search/lib/src/api/search_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ final class SearchClient implements ApiClient {
19521952
);
19531953
}
19541954

1955-
/// Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
1955+
/// Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
19561956
///
19571957
/// Required API Key ACLs:
19581958
/// - search

clients/algoliasearch-client-go/algolia/search/api_search.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/SearchClient.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5025,6 +5025,8 @@ public CompletableFuture<UpdatedAtResponse> saveSynonymsAsync(@Nonnull String in
50255025
* Sends multiple search requests to one or more indices. This can be useful in these cases: -
50265026
* Different indices for different purposes, such as, one index for products, another one for
50275027
* marketing content. - Multiple searches to the same index—for example, with different filters.
5028+
* Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient
5029+
* format, if you already know the return type you want.
50285030
*
50295031
* @param searchMethodParams Muli-search request body. Results are returned in the same order as
50305032
* the requests. (required)
@@ -5045,6 +5047,8 @@ public <T> SearchResponses<T> search(
50455047
* Sends multiple search requests to one or more indices. This can be useful in these cases: -
50465048
* Different indices for different purposes, such as, one index for products, another one for
50475049
* marketing content. - Multiple searches to the same index—for example, with different filters.
5050+
* Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient
5051+
* format, if you already know the return type you want.
50485052
*
50495053
* @param searchMethodParams Muli-search request body. Results are returned in the same order as
50505054
* the requests. (required)
@@ -5059,7 +5063,8 @@ public <T> SearchResponses<T> search(@Nonnull SearchMethodParams searchMethodPar
50595063
* (asynchronously) Sends multiple search requests to one or more indices. This can be useful in
50605064
* these cases: - Different indices for different purposes, such as, one index for products,
50615065
* another one for marketing content. - Multiple searches to the same index—for example, with
5062-
* different filters.
5066+
* different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a
5067+
* more convenient format, if you already know the return type you want.
50635068
*
50645069
* @param searchMethodParams Muli-search request body. Results are returned in the same order as
50655070
* the requests. (required)
@@ -5088,7 +5093,8 @@ public <T> CompletableFuture<SearchResponses<T>> searchAsync(
50885093
* (asynchronously) Sends multiple search requests to one or more indices. This can be useful in
50895094
* these cases: - Different indices for different purposes, such as, one index for products,
50905095
* another one for marketing content. - Multiple searches to the same index—for example, with
5091-
* different filters.
5096+
* different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a
5097+
* more convenient format, if you already know the return type you want.
50925098
*
50935099
* @param searchMethodParams Muli-search request body. Results are returned in the same order as
50945100
* the requests. (required)

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/search/SearchResult.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,34 @@
66
import com.algolia.exceptions.AlgoliaRuntimeException;
77
import com.fasterxml.jackson.annotation.*;
88
import com.fasterxml.jackson.core.*;
9-
import com.fasterxml.jackson.core.type.TypeReference;
109
import com.fasterxml.jackson.databind.*;
10+
import com.fasterxml.jackson.databind.BeanProperty;
1111
import com.fasterxml.jackson.databind.annotation.*;
12+
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
1213
import java.io.IOException;
1314
import java.util.logging.Logger;
1415

1516
/** SearchResult */
1617
@JsonDeserialize(using = SearchResult.Deserializer.class)
1718
public interface SearchResult<T> {
18-
class Deserializer<T> extends JsonDeserializer<SearchResult<T>> {
19+
class Deserializer<T> extends JsonDeserializer<SearchResult<T>> implements ContextualDeserializer {
1920

2021
private static final Logger LOGGER = Logger.getLogger(Deserializer.class.getName());
2122

23+
private JavaType returnType;
24+
25+
public Deserializer() {}
26+
27+
private Deserializer(JavaType returnType) {
28+
this.returnType = returnType;
29+
}
30+
31+
@Override
32+
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) {
33+
JavaType contextualType = ctxt.getContextualType().containedType(0);
34+
return new Deserializer(contextualType);
35+
}
36+
2237
@Override
2338
public SearchResult<T> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
2439
JsonNode tree = jp.readValueAsTree();
@@ -36,7 +51,12 @@ public SearchResult<T> deserialize(JsonParser jp, DeserializationContext ctxt) t
3651
// deserialize SearchResponse
3752
if (tree.isObject()) {
3853
try (JsonParser parser = tree.traverse(jp.getCodec())) {
39-
return parser.readValueAs(new TypeReference<SearchResponse<T>>() {});
54+
// For generic types, the innerType is erased by Java, we need to use the contextual type.
55+
JavaType innerType = ctxt.getTypeFactory().constructParametricType(SearchResponse.class, returnType);
56+
if (parser.getCurrentToken() == null) {
57+
parser.nextToken();
58+
}
59+
return ctxt.readValue(parser, innerType);
4060
} catch (Exception e) {
4161
// deserialization failed, continue
4262
LOGGER.finest("Failed to deserialize oneOf SearchResponse (error: " + e.getMessage() + ") (type: SearchResponse)");

clients/algoliasearch-client-javascript/packages/algoliasearch/lite/src/liteClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export function createLiteClient({
247247
},
248248

249249
/**
250-
* Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
250+
* Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
251251
*
252252
* Required API Key ACLs:
253253
* - search

clients/algoliasearch-client-javascript/packages/client-search/src/searchClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,7 @@ export function createSearchClient({
25612561
},
25622562

25632563
/**
2564-
* Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
2564+
* Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
25652565
*
25662566
* Required API Key ACLs:
25672567
* - search

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/api/SearchClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ public class SearchClient(
11881188
}
11891189

11901190
/**
1191-
* Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
1191+
* Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
11921192
*
11931193
* Required API Key ACLs:
11941194
* - search

clients/algoliasearch-client-php/lib/Api/SearchClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,7 @@ public function saveSynonyms($indexName, $synonymHit, $forwardToReplicas = null,
23402340
}
23412341

23422342
/**
2343-
* Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
2343+
* Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
23442344
*
23452345
* Required API Key ACLs:
23462346
* - search

clients/algoliasearch-client-python/algoliasearch/search/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4473,7 +4473,7 @@ async def search_with_http_info(
44734473
request_options: Optional[Union[dict, RequestOptions]] = None,
44744474
) -> ApiResponse[str]:
44754475
"""
4476-
Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
4476+
Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
44774477
44784478
Required API Key ACLs:
44794479
- search
@@ -4517,7 +4517,7 @@ async def search(
45174517
request_options: Optional[Union[dict, RequestOptions]] = None,
45184518
) -> SearchResponses:
45194519
"""
4520-
Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
4520+
Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
45214521
45224522
Required API Key ACLs:
45234523
- search
@@ -9528,7 +9528,7 @@ def search_with_http_info(
95289528
request_options: Optional[Union[dict, RequestOptions]] = None,
95299529
) -> ApiResponse[str]:
95309530
"""
9531-
Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
9531+
Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
95329532
95339533
Required API Key ACLs:
95349534
- search
@@ -9572,7 +9572,7 @@ def search(
95729572
request_options: Optional[Union[dict, RequestOptions]] = None,
95739573
) -> SearchResponses:
95749574
"""
9575-
Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
9575+
Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
95769576
95779577
Required API Key ACLs:
95789578
- search

clients/algoliasearch-client-ruby/lib/algolia/api/search_client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,7 +2603,7 @@ def save_synonyms(
26032603
@api_client.deserialize(response.body, request_options[:debug_return_type] || "Search::UpdatedAtResponse")
26042604
end
26052605

2606-
# Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
2606+
# Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
26072607
#
26082608
# Required API Key ACLs:
26092609
# - search
@@ -2635,7 +2635,7 @@ def search_with_http_info(search_method_params, request_options = {})
26352635
@api_client.call_api(:POST, path, new_options)
26362636
end
26372637

2638-
# Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters.
2638+
# Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
26392639
#
26402640
# Required API Key ACLs:
26412641
# - search

clients/algoliasearch-client-scala/src/main/scala/algoliasearch/api/SearchClient.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,8 @@ class SearchClient(
15231523

15241524
/** Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for
15251525
* different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the
1526-
* same index—for example, with different filters.
1526+
* same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the
1527+
* results in a more convenient format, if you already know the return type you want.
15271528
*
15281529
* Required API Key ACLs:
15291530
* - search

clients/algoliasearch-client-swift/Sources/Search/SearchClient.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3541,7 +3541,8 @@ open class SearchClient {
35413541
// Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices
35423542
// for different purposes, such as, one index for products, another one for marketing content. - Multiple searches
35433543
// to
3544-
// the same index—for example, with different filters.
3544+
// the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get
3545+
// the results in a more convenient format, if you already know the return type you want.
35453546
// Required API Key ACLs:
35463547
// - search
35473548
//

0 commit comments

Comments
 (0)