Algolia Recommend Rust Client
📦 Install
$ cargo add algolia-recommend-rs
⚡️ Quick start
use algolia_recommend_rs::{RecommendClient, models::{RecommendRequest, Model, TrendingFacetsRequest}};
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct Product {
title: Option<String>,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = RecommendClient::new("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
let requests = vec![
RecommendRequest {
index_name: "products".to_string(),
model: Model::BoughtTogether,
object_id: Some("example-object-id".to_string()),
threshold: Some(0),
max_recommendations: None,
facet_name: None,
query_parameters: None,
},
RecommendRequest {
index_name: "products".to_string(),
model: Model::TrendingItems,
object_id: None,
threshold: Some(0),
max_recommendations: None,
facet_name: None,
query_parameters: None,
},
];
let recs = client.get_recommendations::<Product>(requests).await?;
println!("results: {}", recs.results.len());
for result in recs.results.iter() {
for hit in result.hits.iter() {
println!("objectID={} score={:?} payload={:?}", hit.object_id, hit.score, hit.payload);
}
}
let trending = client
.get_trending_facets(vec![TrendingFacetsRequest::new("products", "category")])
.await?;
println!("trending results: {}", trending.results.len());
Ok(())
}
🦀 Notes
- The library is lenient in (de)serialization to stay forward-compatible with Algolia responses.
- This is not an official API client, this is a personal project done to learn Rust.
- This project is not covered by Algolia SLA
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED (see LICENSE)
📜 License
MIT