Skip to content

Commit

Permalink
format all
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillFish8 committed Aug 26, 2021
1 parent 908e6d8 commit 99523f2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
16 changes: 12 additions & 4 deletions engine/src/index/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,15 @@ impl IndexReaderHandler {
&self.name,
time_taken,
limit,
if let QueryMode::Fuzzy = mode { if use_fast_fuzzy { "FastFuzzy".to_string() } else { "Fuzzy".to_string() } } else { format!("{:?}", mode) },
if let QueryMode::Fuzzy = mode {
if use_fast_fuzzy {
"FastFuzzy".to_string()
} else {
"Fuzzy".to_string()
}
} else {
format!("{:?}", mode)
},
res.count
);

Expand Down Expand Up @@ -419,14 +427,14 @@ fn parse_fast_fuzzy_query(
for word in words.iter() {
if !stop_words.contains(*word) {
ignore_stop_words = true;
break
break;
}
}
}

for search_term in words.iter() {
if ignore_stop_words && stop_words.contains(*search_term) {
continue
continue;
}

for (field, boost) in search_fields.iter() {
Expand Down Expand Up @@ -574,7 +582,7 @@ fn search(
);

Ok(QueryResults {
time_taken: 0f32, // filled in by handler later
time_taken: 0f32, // filled in by handler later
hits,
count,
})
Expand Down
17 changes: 10 additions & 7 deletions engine/src/stop_words.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::io::Write;
use anyhow::{Result, Error};
use once_cell::sync::OnceCell;
use anyhow::{Error, Result};
use flate2::write::GzDecoder;
use hashbrown::HashSet;
use once_cell::sync::OnceCell;
use std::io::Write;

static STOP_WORDS: OnceCell<Vec<String>> = OnceCell::new();
static STOP_WORDS_HASHSET: OnceCell<HashSet<String>> = OnceCell::new();
Expand All @@ -14,7 +14,7 @@ pub(crate) fn init_stop_words() -> Result<()> {
let data = data.finish()?;

let words = String::from_utf8(data)
.map_err(|_| Error::msg("failed to parse stop words from linked data."))?;
.map_err(|_| Error::msg("failed to parse stop words from linked data."))?;

let mut hashed_data = HashSet::new();
let mut data = vec![];
Expand All @@ -35,15 +35,18 @@ pub(crate) fn get_stop_words() -> Result<Vec<String>> {
if let Some(words) = STOP_WORDS.get() {
Ok(words.clone())
} else {
Err(Error::msg("stop words was not initialised at time of calling."))
Err(Error::msg(
"stop words was not initialised at time of calling.",
))
}
}

pub(crate) fn get_hashset_words<'a>() -> Result<&'a HashSet<String>> {
if let Some(words) = STOP_WORDS_HASHSET.get() {
Ok(words)
} else {
Err(Error::msg("stop words was not initialised at time of calling."))
Err(Error::msg(
"stop words was not initialised at time of calling.",
))
}
}

7 changes: 5 additions & 2 deletions engine/src/structures.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use hashbrown::HashMap;
use serde::{Deserialize, Serialize};

use tantivy::schema::{IntOptions, Schema as InternalSchema, SchemaBuilder as InternalSchemaBuilder, STORED, STRING, TEXT, Cardinality, Field};
use tantivy::{DateTime, Score};
use crate::helpers::hash;
use tantivy::schema::{
Cardinality, Field, IntOptions, Schema as InternalSchema,
SchemaBuilder as InternalSchemaBuilder, STORED, STRING, TEXT,
};
use tantivy::{DateTime, Score};

/// A declared schema field type.
///
Expand Down

0 comments on commit 99523f2

Please sign in to comment.