Skip to content

Commit

Permalink
fix rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisMacNaughton committed Jul 29, 2016
1 parent 660b2fa commit 1eed419
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
12 changes: 5 additions & 7 deletions src/analyzers/standard_analyzer.rs
Expand Up @@ -35,7 +35,7 @@ mod tests {


impl StandardAnalyzer {
fn escape(body: String) -> String {
fn escape(body: String) -> String {
let mut body = body;
body = body.chars().filter(|ch| ch.is_alphanumeric()).collect();
body
Expand All @@ -48,10 +48,9 @@ impl Analyzer for StandardAnalyzer {
}

fn tokenize(body: &String) -> Vec<String> {
body
.split_whitespace()
body.split_whitespace()
.map(|s| s.to_lowercase())
.map(|s| StandardAnalyzer::escape(s) )
.map(|s| StandardAnalyzer::escape(s))
.collect()
}

Expand Down Expand Up @@ -79,15 +78,14 @@ impl Analyzer for StandardAnalyzer {
// let mut count = word_count.entry(word).or_insert(0);
// *count += 1;
// }

// let mut extra_tokens = HashMap::new();



ParsedDocument {
document: doc,
tokens: full_word_count,
// extra_tokens:
tokens: full_word_count, // extra_tokens:
}
}
}
8 changes: 4 additions & 4 deletions src/document/mod.rs
Expand Up @@ -14,12 +14,12 @@ impl Document {
for (k, v) in &attrs {
new_attrs.insert(k.to_string(), v.to_string());
}
Document {
attrs: new_attrs,
}
Document { attrs: new_attrs }
}

pub fn tokenize<T: Fn(&String)->Vec<String>>(&self, func: &T) -> HashMap<String, Vec<String>> {
pub fn tokenize<T: Fn(&String) -> Vec<String>>(&self,
func: &T)
-> HashMap<String, Vec<String>> {
let mut parts = HashMap::new();
for (key, body) in &self.attrs {
parts.insert(key.to_owned(), (func)(body));
Expand Down
18 changes: 9 additions & 9 deletions src/index/mod.rs
Expand Up @@ -13,7 +13,7 @@ mod tests {
use analyzers::standard_analyzer::StandardAnalyzer;
use {Document, Search};
use std::collections::HashMap;

#[test]
fn it_queries() {

Expand All @@ -33,7 +33,7 @@ mod tests {
assert_eq!(*result.first().unwrap(), document);
}


#[test]
fn it_queries_wildcard() {

Expand Down Expand Up @@ -122,18 +122,18 @@ impl<T: Analyzer> Index<T> {
Some(s) => {
for (ref count, ref doc_ids) in s {
for doc_id in doc_ids.iter() {
docs.push((*count.clone(), self.documents.get(*doc_id).unwrap()))
docs.push((*count.clone(),
self.documents.get(*doc_id).unwrap()))
}
}

},
None => continue
}
None => continue,
}
}
},
None => return docs
}
None => return docs,
}

// docs.push(self.documents.first().unwrap());
docs
}
Expand Down
8 changes: 3 additions & 5 deletions src/search.rs
Expand Up @@ -5,17 +5,15 @@ use std::hash::Hash;

#[derive(Debug, Clone, PartialEq)]
pub struct Search {
pub options: HashMap<String, String>
pub options: HashMap<String, String>,
}

impl Search {
pub fn from_attributes<T: Display + Debug + Eq + Hash>(attrs: HashMap<T, T>) -> Search {
let mut new_attrs = HashMap::new();
let mut new_attrs = HashMap::new();
for (k, v) in &attrs {
new_attrs.insert(k.to_string(), v.to_string());
}
Search {
options: new_attrs,
}
Search { options: new_attrs }
}
}

0 comments on commit 1eed419

Please sign in to comment.