From 00225d71ea794f413534612d80b6c1722b281349 Mon Sep 17 00:00:00 2001 From: Cristian Medeiros Date: Mon, 20 Jun 2016 22:13:09 -0300 Subject: [PATCH 1/2] - Updated Url implementation - --- Cargo.toml | 2 +- src/client.rs | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a0ed214..7d36458 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ authors = ["Valentin Vasilyev ", "Dzmitry Misiuk [dependencies] -url = "0.5.9" +url = "*" hyper = "*" rustc-serialize = "*" time="*" diff --git a/src/client.rs b/src/client.rs index 8f9f308..b9bb594 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,4 +1,4 @@ -use url::{Url, UrlParser}; +use url::Url; use rustc_serialize::{json}; use hyper::error::Error; @@ -29,33 +29,33 @@ pub struct SolrClient { impl SolrClient { fn build_update_url(url: &Url) -> Url{ - let mut url_parser = UrlParser::new(); - url_parser.base_url(url).parse("./update").unwrap() + let mut url_parser = Url::parse(url.as_str()).unwrap(); + url_parser.join("./update").unwrap() } fn build_select_url(url: &Url) -> Url { - let mut url_parser = UrlParser::new(); - url_parser.base_url(url).parse("./select").unwrap() + let mut url_parser = Url::parse(url.as_str()).unwrap(); + url_parser.join("./select").unwrap() } fn build_commit_url(url: &Url) -> Url { - let mut url_parser = UrlParser::new(); - url_parser.base_url(url).parse("./update?commit=true").unwrap() + let mut url_parser = Url::parse(url.as_str()).unwrap(); + url_parser.join("./update?commit=true").unwrap() } fn build_ping_url(url: &Url) -> Url { - let mut url_parser = UrlParser::new(); - url_parser.base_url(url).parse("./admin/ping?wt=json").unwrap() + let mut url_parser = Url::parse(url.as_str()).unwrap(); + url_parser.join("./admin/ping?wt=json").unwrap() } fn build_rollback_url(url: &Url) -> Url { - let mut url_parser = UrlParser::new(); - url_parser.base_url(url).parse("./update?rollback=true").unwrap() + let mut url_parser = Url::parse(url.as_str()).unwrap(); + url_parser.join("./update?rollback=true").unwrap() } fn build_optimize_url(url: &Url) -> Url { - let mut url_parser = UrlParser::new(); - url_parser.base_url(url).parse("./update?optimize=true").unwrap() + let mut url_parser = Url::parse(url.as_str()).unwrap(); + url_parser.join("./update?optimize=true").unwrap() } /// Creates a new instance of Solr. @@ -85,8 +85,14 @@ impl SolrClient { /// Performs Solr query pub fn query(&self, query: &SolrQuery) -> SolrQueryResult { + let mut query_url = self.select_url.clone(); - query_url.set_query_from_pairs(query.to_pairs().iter().map(|&(ref x, ref y)| (&x[..], &y[..]))); + + for q in query.to_pairs() { + let (parameter, value) = q; + query_url.query_pairs_mut().append_pair(¶meter, &value); + } + let http_result = http_utils::get(&query_url); handle_http_query_result(http_result) } From 877c08e4965be2025cdd53dd515498eab6c25ffb Mon Sep 17 00:00:00 2001 From: Cristian Medeiros Date: Mon, 20 Jun 2016 23:02:27 -0300 Subject: [PATCH 2/2] - Fixing Url crate version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7d36458..59bae3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ authors = ["Valentin Vasilyev ", "Dzmitry Misiuk [dependencies] -url = "*" +url = "1.1.1" hyper = "*" rustc-serialize = "*" time="*"