algolia_client_recommend 1.2.1 copy "algolia_client_recommend: ^1.2.1" to clipboard
algolia_client_recommend: ^1.2.1 copied to clipboard

A sub-package of the AlgoliaSearch library, offering recommend-specific functionalities for enhanced search and discovery in Dart/Flutter apps.

example/example.dart

import 'package:algolia_client_recommend/algolia_client_recommend.dart';

void main() async {
  // Creating an instance of the recommend client with the provided App ID and API key.
  final client = RecommendClient(
    appId: 'latency',
    apiKey: '6be0576ff61c053d5f9a3225e2a90f76',
  );

  // Creating recommendation requests for different products.
  var requests = [
    RecommendationsQuery(
      model: RecommendationModels.relatedProducts,
      objectID: '6445156',
      indexName: 'instant_search',
      threshold: 70,
      maxRecommendations: 3,
    ),
    RecommendationsQuery(
      model: RecommendationModels.relatedProducts,
      objectID: '6443034',
      indexName: 'instant_search',
      threshold: 70,
      maxRecommendations: 3,
    )
  ];

  // Fetching recommendations from Algolia using the above requests.
  final response = await client.getRecommendations(
    getRecommendationsParams: GetRecommendationsParams(requests: requests),
  );

  // Printing the recommendations.
  printRecommendations(response);

  // Close the client and dispose of all underlying resources.
  client.dispose();
}

/// Prints the search hits.
void printRecommendations(GetRecommendationsResponse response) {
  final results = response.results;
  if (results == null) {
    print("No recommendations found");
    return;
  }

  // Loop over each result and map over the search hits,
  // converting each hit to a product.
  for (final result in results) {
    final hits = result.hits.map((e) => product(e));
    for (final (name, brand) in hits) {
      print("* $name ($brand)");
    }
  }
}

/// Converts a JSON object into a product tuple of (name, brand).
/// A data class with json deserialization can also be used.
(String, String) product(Map<String, dynamic> json) =>
    (json['name'] as String, json['brand'] as String);
3
likes
0
pub points
64%
popularity

Publisher

verified publisheralgolia.com

A sub-package of the AlgoliaSearch library, offering recommend-specific functionalities for enhanced search and discovery in Dart/Flutter apps.

Homepage
Repository (GitHub)
View/report issues

Topics

#search #discovery

License

unknown (LICENSE)

Dependencies

algolia_client_core, collection, json_annotation

More

Packages that depend on algolia_client_recommend