Skip to main content

headless_engine/google/
types.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize, Deserialize, Clone, Default)]
4pub struct GoogleSearchResult {
5    pub query: String,
6    pub title: String,
7    pub ai_overview: Option<String>,
8    pub knowledge_panel: Option<String>,
9    pub organic_results: Vec<OrganicResult>,
10    pub related_questions: Vec<String>,
11}
12
13#[derive(Debug, Serialize, Deserialize, Clone, Default)]
14pub struct OrganicResult {
15    pub title: String,
16    pub link: String,
17    pub snippet: String,
18}
19
20impl GoogleSearchResult {
21    pub fn to_markdown(&self) -> String {
22        let mut md = format!("# {} - Google Search\n\n", self.title);
23        if let Some(ai) = &self.ai_overview {
24            md.push_str("## ✨ AI Overview\n");
25            md.push_str(ai);
26            md.push_str("\n\n");
27        }
28        if let Some(kp) = &self.knowledge_panel {
29            md.push_str("## 🧠 Knowledge Panel\n");
30            md.push_str(kp);
31            md.push_str("\n\n");
32        }
33        if !self.organic_results.is_empty() {
34            md.push_str("## 🔍 Organic Results\n\n");
35            for (i, res) in self.organic_results.iter().enumerate() {
36                md.push_str(&format!("### {}. [{}]({})\n{}\n\n", i + 1, res.title, res.link, res.snippet));
37            }
38        }
39        if !self.related_questions.is_empty() {
40            md.push_str("## ❓ People Also Ask\n");
41            for q in &self.related_questions {
42                md.push_str(&format!("- {}\n", q));
43            }
44        }
45        md
46    }
47}
48
49// Minimal implementations for the other 30 capabilities
50// Since there are 31 methods, we will define a generalized struct for the ones we don't have full extractors for yet.
51#[derive(Debug, Serialize, Deserialize, Clone, Default)]
52pub struct GenericGoogleResult {
53    pub query: String,
54    pub title: String,
55    pub raw_markdown: String,
56}
57
58impl GenericGoogleResult {
59    pub fn to_markdown(&self) -> String {
60        self.raw_markdown.clone()
61    }
62}
63
64#[derive(Debug, Serialize, Deserialize, Clone, Default)]
65pub struct GoogleAutocompleteResult {
66    pub query: String,
67    pub suggestions: Vec<String>,
68}
69
70impl GoogleAutocompleteResult {
71    pub fn to_markdown(&self) -> String {
72        let mut md = format!("# Autocomplete for '{}'\n\n", self.query);
73        for s in &self.suggestions {
74            md.push_str(&format!("- {}\n", s));
75        }
76        md
77    }
78}
79
80// You can expand these structs as specific parsers are added.