Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Updated Url implementation #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = ["Valentin Vasilyev <[email protected]>", "Dzmitry Misiuk


[dependencies]
url = "0.5.9"
url = "1.1.1"
hyper = "*"
rustc-serialize = "*"
time="*"
34 changes: 20 additions & 14 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use url::{Url, UrlParser};
use url::Url;
use rustc_serialize::{json};
use hyper::error::Error;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(&parameter, &value);
}

let http_result = http_utils::get(&query_url);
handle_http_query_result(http_result)
}
Expand Down