Skip to content

Commit

Permalink
feat(dart): search helpers searchForHits and searchForFacets
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#2146

Co-authored-by: Mouaad Aallam <mouaad.aallam@algolia.com>
  • Loading branch information
algolia-bot and aallam committed Oct 18, 2023
1 parent 85712d3 commit 3b0e44f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/algoliasearch/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void main() async {
hitsPerPage: 5,
);
// Execute the multi-search request.
final responseMulti = await client.searchMultiIndex(
queries: [querySuggestions, queryHits],
final responseMulti = await client.searchForHits(
requests: [querySuggestions, queryHits],
);
// Decompose the search results into separate results and suggestions.
final [searchResult, suggestionsResult] = responseMulti.toList();
Expand Down
32 changes: 30 additions & 2 deletions packages/algoliasearch/lib/src/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,42 @@ extension SearchClientExt on SearchClient {
return SearchResponse.fromJson(response.results.first);
}

/// Calls the `search` method but with certainty that we will only request
/// Algolia records (hits).
Future<Iterable<SearchResponse>> searchForHits({
required List<SearchForHits> requests,
SearchStrategy? strategy,
RequestOptions? requestOptions,
}) async {
final request = SearchMethodParams(requests: requests, strategy: strategy);
return search(searchMethodParams: request, requestOptions: requestOptions)
.then((res) => res.results.map((e) => SearchResponse.fromJson(e)));
}

/// Perform a search operation targeting one index.
@Deprecated("renamed to `searchForHits`")
Future<Iterable<SearchResponse>> searchMultiIndex({
required List<SearchForHits> queries,
SearchStrategy? strategy,
RequestOptions? requestOptions,
}) {
final request = SearchMethodParams(requests: queries, strategy: strategy);
return searchForHits(
requests: queries,
strategy: strategy,
requestOptions: requestOptions,
);
}

/// Calls the `search` method but with certainty that we will only request
/// Algolia facets.
Future<Iterable<SearchForFacetValuesResponse>> searchForFacets({
required List<SearchForFacets> requests,
SearchStrategy? strategy,
RequestOptions? requestOptions,
}) async {
final request = SearchMethodParams(requests: requests, strategy: strategy);
return search(searchMethodParams: request, requestOptions: requestOptions)
.then((res) => res.results.map((e) => SearchResponse.fromJson(e)));
.then((res) =>
res.results.map((e) => SearchForFacetValuesResponse.fromJson(e)));
}
}
32 changes: 30 additions & 2 deletions packages/client_search/lib/src/extension/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,42 @@ extension SearchClientExt on SearchClient {
return SearchResponse.fromJson(response.results.first);
}

/// Calls the `search` method but with certainty that we will only request
/// Algolia records (hits).
Future<Iterable<SearchResponse>> searchForHits({
required List<SearchForHits> requests,
SearchStrategy? strategy,
RequestOptions? requestOptions,
}) async {
final request = SearchMethodParams(requests: requests, strategy: strategy);
return search(searchMethodParams: request, requestOptions: requestOptions)
.then((res) => res.results.map((e) => SearchResponse.fromJson(e)));
}

/// Perform a search operation targeting one index.
@Deprecated("renamed to `searchForHits`")
Future<Iterable<SearchResponse>> searchMultiIndex({
required List<SearchForHits> queries,
SearchStrategy? strategy,
RequestOptions? requestOptions,
}) {
final request = SearchMethodParams(requests: queries, strategy: strategy);
return searchForHits(
requests: queries,
strategy: strategy,
requestOptions: requestOptions,
);
}

/// Calls the `search` method but with certainty that we will only request
/// Algolia facets.
Future<Iterable<SearchForFacetValuesResponse>> searchForFacets({
required List<SearchForFacets> requests,
SearchStrategy? strategy,
RequestOptions? requestOptions,
}) async {
final request = SearchMethodParams(requests: requests, strategy: strategy);
return search(searchMethodParams: request, requestOptions: requestOptions)
.then((res) => res.results.map((e) => SearchResponse.fromJson(e)));
.then((res) =>
res.results.map((e) => SearchForFacetValuesResponse.fromJson(e)));
}
}

0 comments on commit 3b0e44f

Please sign in to comment.