Skip to content

Commit

Permalink
Cleanup Option::from/None to Some/None
Browse files Browse the repository at this point in the history
  • Loading branch information
ang-zeyu committed Aug 23, 2021
1 parent 872ff92 commit 4ea6f76
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/morsels_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Default for MorselsLanguageConfig {
fn default() -> Self {
MorselsLanguageConfig {
lang: get_default_language(),
options: Option::None,
options: None,
}
}
}
2 changes: 1 addition & 1 deletion packages/morsels_common/src/tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub trait Tokenizer {

fn is_stop_word(&self, term: &str) -> bool;

// If true, simply return Option::None / An empty hashmap for the below two methods
// If true, simply return None / An empty hashmap for the below two methods
fn use_default_trigram(&self) -> bool;

fn get_best_corrected_term(&self, term: &str, dictionary: &FxHashMap<Rc<SmartString>, Rc<TermInfo>>) -> Option<String>;
Expand Down
2 changes: 1 addition & 1 deletion packages/morsels_indexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ fn main() {
}
}

indexer.finish_writing_docs(Option::from(now));
indexer.finish_writing_docs(Some(now));
}
2 changes: 1 addition & 1 deletion packages/morsels_indexer/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn worker (
// return the indexed documents...
sndr.send(WorkerToMainMessage {
id,
block_index_results: Option::from(WorkerBlockIndexResults {
block_index_results: Some(WorkerBlockIndexResults {
terms: std::mem::take(&mut doc_miner.terms),
doc_infos: std::mem::replace(
&mut doc_miner.doc_infos, Vec::with_capacity(expected_num_docs_per_reset)
Expand Down
12 changes: 6 additions & 6 deletions packages/morsels_search/src/Searcher/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ impl Ord for DocResult {
impl PartialOrd for DocResult {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.1 < other.1 {
Option::from(Ordering::Less)
Some(Ordering::Less)
} else if self.1 > other.1 {
Option::from(Ordering::Greater)
Some(Ordering::Greater)
} else {
Option::from(Ordering::Equal)
Some(Ordering::Equal)
}
}
}
Expand Down Expand Up @@ -77,11 +77,11 @@ impl Ord for Position {
impl PartialOrd for Position {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.pos < other.pos {
Option::from(Ordering::Greater)
Some(Ordering::Greater)
} else if self.pos == other.pos {
Option::from(Ordering::Equal)
Some(Ordering::Equal)
} else {
Option::from(Ordering::Less)
Some(Ordering::Less)
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions packages/morsels_search/src/Searcher/query_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn handle_unary_op(mut query_part: QueryPart, operator_stack: &mut Vec<UnaryOp>)
terms: None,
part_type: QueryPartType::NOT,
field_name: None,
children: Option::from(vec![query_part]),
children: Some(vec![query_part]),
}
},
UnaryOp::FIELD(field_name) => {
Expand Down Expand Up @@ -111,23 +111,23 @@ fn handle_terminator(
is_stop_word_removed: false,
should_expand: tokenize_result.should_expand,
is_expanded: false,
original_terms: Option::None,
terms: Option::from(vec![term]),
original_terms: None,
terms: Some(vec![term]),
part_type: QueryPartType::TERM,
field_name: None,
children: Option::None,
children: None,
}, operator_stack));
} else {
query_parts.push(QueryPart {
is_corrected: false,
is_stop_word_removed: false,
should_expand: tokenize_result.should_expand,
is_expanded: false,
original_terms: Option::None,
terms: Option::from(vec![term]),
original_terms: None,
terms: Some(vec![term]),
part_type: QueryPartType::TERM,
field_name: None,
children: Option::None,
children: None,
});
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ pub fn parse_query(query: String, tokenizer: &Box<dyn Tokenizer>) -> Vec<QueryPa
QueryParseState::QUOTE | QueryParseState::PARENTHESES => {
let char_to_match = if let QueryParseState::QUOTE = query_parse_state { '"' } else { ')' };
if !did_encounter_escape && c == char_to_match {
let content: String = collect_slice(&query_chars, i, j, &escape_indices);
let content = collect_slice(&query_chars, i, j, &escape_indices);
let term_parttype_children = if let QueryParseState::QUOTE = query_parse_state {
(Some(tokenizer.wasm_tokenize(content).terms), QueryPartType::PHRASE, None)
} else {
Expand Down Expand Up @@ -243,11 +243,11 @@ pub fn parse_query(query: String, tokenizer: &Box<dyn Tokenizer>) -> Vec<QueryPa
is_stop_word_removed: false,
should_expand: false,
is_expanded: false,
original_terms: Option::None,
terms: Option::None,
original_terms: None,
terms: None,
part_type: QueryPartType::AND,
field_name: None,
children: Option::from(if let Some(last_curr_query_part) = last_curr_query_part {
children: Some(if let Some(last_curr_query_part) = last_curr_query_part {
vec![last_curr_query_part]
} else {
vec![]
Expand Down
6 changes: 3 additions & 3 deletions packages/morsels_search/src/Searcher/query_preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ impl Searcher {
if allow_stop_word_removal && self.tokenizer.is_stop_word(term) {
query_part.is_stop_word_removed = true;
if let None = query_part.original_terms {
query_part.original_terms = Option::from(terms.clone());
query_part.original_terms = Some(terms.clone());
}
terms.remove(term_idx);
continue;
}

if let Option::None = self.dictionary.get_term_info(term) {
if let None = self.dictionary.get_term_info(term) {
query_part.is_corrected = true;
if let None = query_part.original_terms {
query_part.original_terms = Option::from(terms.clone());
query_part.original_terms = Some(terms.clone());
}

let best_corrected_term = if self.tokenizer.use_default_trigram() {
Expand Down
22 changes: 11 additions & 11 deletions packages/morsels_search/src/Searcher/query_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ impl Searcher {
include_in_proximity_ranking: true,
term_docs: Vec::new(),
idf: 0.0,
term: Option::None,
term_info: Option::None,
term: None,
term_info: None,
max_term_score: 0.0,
};

Expand Down Expand Up @@ -180,8 +180,8 @@ impl Searcher {
include_in_proximity_ranking: true,
term_docs: Vec::new(),
idf: 0.0,
term: Option::None,
term_info: Option::None,
term: None,
term_info: None,
max_term_score: 0.0,
};

Expand Down Expand Up @@ -235,8 +235,8 @@ impl Searcher {
include_in_proximity_ranking: false,
term_docs: Vec::new(),
idf: 0.0,
term: Option::None,
term_info: Option::None,
term: None,
term_info: None,
max_term_score: 0.0,
};

Expand Down Expand Up @@ -287,9 +287,9 @@ impl Searcher {
);

if child_postings_lists.len() == 0 {
return Option::None;
return None;
} else if child_postings_lists.len() == 1 {
return Option::from(child_postings_lists.pop().unwrap());
return Some(child_postings_lists.pop().unwrap());
}

let mut doc_heap: BinaryHeap<Reverse<PlIterator>> = child_postings_lists
Expand All @@ -305,8 +305,8 @@ impl Searcher {
include_in_proximity_ranking: true,
term_docs: Vec::new(),
idf: 0.0,
term: Option::None,
term_info: Option::None,
term: None,
term_info: None,
max_term_score: 0.0,
};

Expand Down Expand Up @@ -350,7 +350,7 @@ impl Searcher {

new_pl.calc_pseudo_idf(self.doc_info.num_docs);

Option::from(Rc::new(new_pl))
Some(Rc::new(new_pl))
}

fn filter_field_postings_list(&self, field_name: &str, pl: &mut Rc<PostingsList>) {
Expand Down
10 changes: 5 additions & 5 deletions packages/morsels_search/src/Searcher/query_retriever.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Searcher {
&& last_query_part.should_expand
&& !last_query_part.is_stop_word_removed {
if let None = last_query_part.original_terms {
last_query_part.original_terms = Option::from(last_query_part.terms.clone());
last_query_part.original_terms = last_query_part.terms.clone();
}

let expanded_terms = if self.tokenizer.use_default_trigram() {
Expand Down Expand Up @@ -58,7 +58,7 @@ impl Searcher {
should_expand: false,
is_expanded: false,
original_terms: None,
terms: Option::from(vec![term.clone()]),
terms: Some(vec![term.clone()]),
part_type: QueryPartType::TERM,
field_name: last_query_part.field_name.clone(),
children: None,
Expand Down Expand Up @@ -94,16 +94,16 @@ impl Searcher {
let mut idf = 0.0;
let term_info = if let Some(term_info_rc) = self.dictionary.get_term_info(term) {
idf = term_info_rc.idf;
Option::from(Rc::clone(term_info_rc))
Some(Rc::clone(term_info_rc))
} else {
Option::None
None
};
let postings_list = PostingsList {
weight: 1.0,
include_in_proximity_ranking: true,
term_docs: Vec::new(),
idf,
term: Option::from(term.clone()),
term: Some(term.clone()),
term_info,
max_term_score: 0.0,
};
Expand Down
8 changes: 4 additions & 4 deletions packages/morsels_search/src/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ pub trait SearchDictionary {

impl SearchDictionary for Dictionary {
fn get_best_corrected_term(&self, misspelled_term: &str) -> Option<std::string::String> {
let mut best_term = Option::None;
let mut best_term = None;
let mut min_idf = f64::MAX;
for term in self.get_corrected_terms(misspelled_term) {
let term_info = self.term_infos.get(&term).unwrap();
if term_info.idf < min_idf {
min_idf = term_info.idf;
best_term = Option::from(term);
best_term = Some(term);
}
};

if let Some(best_term) = best_term {
let normal_string: std::string::String = std::string::String::from(&best_term[..]);
Option::from(normal_string)
Some(normal_string)
} else {
Option::None
None
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/morsels_search/src/postings_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'a> Ord for PlIterator<'a> {

impl<'a> PartialOrd for PlIterator<'a> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Option::from(self.td.unwrap().doc_id.cmp(&other.td.unwrap().doc_id))
Some(self.td.unwrap().doc_id.cmp(&other.td.unwrap().doc_id))
}
}

Expand Down Expand Up @@ -191,7 +191,7 @@ impl PostingsList {
num_pls_per_dir: u32,
with_positions: bool,
) -> Result<(), JsValue> {
if let Option::None = self.term_info {
if let None = self.term_info {
return Ok(());
}

Expand Down

0 comments on commit 4ea6f76

Please sign in to comment.