|
2 | 2 | //! by querying the upstream qwant search engine with user provided query and with a page
|
3 | 3 | //! number if provided.
|
4 | 4 |
|
| 5 | +use std::borrow::Cow; |
5 | 6 | use std::collections::HashMap;
|
6 | 7 |
|
7 | 8 | use reqwest::header::HeaderMap;
|
8 |
| -use reqwest::Client; |
| 9 | +use reqwest::{Client, Url}; |
9 | 10 | use serde::Deserialize;
|
10 | 11 |
|
11 | 12 | use crate::models::aggregation_models::SearchResult;
|
@@ -118,7 +119,20 @@ impl SearchEngine for Qwant {
|
118 | 119 | let results_per_page = 10;
|
119 | 120 | let start_result = results_per_page * page;
|
120 | 121 |
|
121 |
| - let url: String = format!("https://api.qwant.com/v3/search/web?q={query}&count={results_per_page}&locale=en_US&offset={start_result}&safesearch={safe_search}&device=desktop&tgp=2&displayed=true"); |
| 122 | + let url = Url::parse_with_params( |
| 123 | + "https://api.qwant.com/v3/search/web", |
| 124 | + &[ |
| 125 | + ("q", Cow::from(query)), |
| 126 | + ("count", results_per_page.to_string().into()), |
| 127 | + ("locale", "en_US".into()), |
| 128 | + ("offset", start_result.to_string().into()), |
| 129 | + ("safesearch", safe_search.to_string().into()), |
| 130 | + ("device", "desktop".into()), |
| 131 | + ("tgb", "2".into()), |
| 132 | + ("displayed", "true".into()), |
| 133 | + ], |
| 134 | + ) |
| 135 | + .change_context(EngineError::UnexpectedError)?; |
122 | 136 |
|
123 | 137 | let header_map = HeaderMap::try_from(&HashMap::from([
|
124 | 138 | ("User-Agent".to_string(), user_agent.to_string()),
|
|
0 commit comments