finance_query/models/recommendation/
data.rs

1use super::SimilarSymbol;
2/// Recommendation aggregate module
3///
4/// Contains the fully typed Recommendation structure for similar/recommended symbols.
5use serde::{Deserialize, Serialize};
6
7/// Fully typed recommendation data
8///
9/// Aggregates the queried symbol and its recommendations into a single
10/// convenient structure. This is the recommended type for serialization
11/// and API responses.
12///
13/// Note: This struct cannot be manually constructed - use `Ticker::recommendations()` to obtain recommendations.
14#[non_exhaustive]
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Recommendation {
17    /// Symbol that was queried
18    pub symbol: String,
19
20    /// Recommended/similar symbols with scores
21    pub recommendations: Vec<SimilarSymbol>,
22}
23
24impl Recommendation {
25    /// Get just the symbol strings
26    pub fn symbols(&self) -> Vec<&str> {
27        self.recommendations
28            .iter()
29            .map(|s| s.symbol.as_str())
30            .collect()
31    }
32
33    /// Get the number of recommendations
34    pub fn count(&self) -> usize {
35        self.recommendations.len()
36    }
37}
38
39#[cfg(feature = "dataframe")]
40impl Recommendation {
41    /// Converts the recommendations to a polars DataFrame.
42    pub fn to_dataframe(&self) -> ::polars::prelude::PolarsResult<::polars::prelude::DataFrame> {
43        SimilarSymbol::vec_to_dataframe(&self.recommendations)
44    }
45}