From 4bf31c45284b869a690d510300aa0a29a572f73c Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Tue, 19 Jun 2018 09:52:31 +0530 Subject: Add basic search functionality --- src/content.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/content.rs b/src/content.rs index 67e8d24..17ad40a 100644 --- a/src/content.rs +++ b/src/content.rs @@ -1,4 +1,4 @@ -pub fn url_gen(title: &str) -> String { +pub fn query_url_gen(title: &str) -> String { title.replace(" ", "%20"); @@ -8,8 +8,24 @@ pub fn url_gen(title: &str) -> String { url.push_str("action=query&"); url.push_str("format=json&"); url.push_str("prop=extracts&"); - url.push_str(format!("titles={}", title)); + url.push_str(format!("titles={}&", title)); url.push_str("explaintext=1"); + + url +} + +pub fn search_url_gen(search: &str) -> String { + // /w/api.php?action=opensearch&format=json&search=dota%202&limit=5; + + search.replace(" ", "%20"); + + let url = "https://en.wikipedia.org"; + url.push_str("w/api.php?"); + url.push_str("action=opensearch&"); + url.push_str("format=json&"); + url.push_str(format!("search={}&", search)); + url.push_str("limit=5"); + } pub fn get_extract(title: &str, red: Response) -> String { -- cgit v1.2.3