String closeness seems alright
Might be worth sorting by relevance
This commit is contained in:
@@ -38,49 +38,19 @@ pub fn get_all_lowercase_card_names() -> Vec<String> {
|
||||
card_names
|
||||
}
|
||||
|
||||
pub fn update_db_with_file(file: PathBuf) -> bool {
|
||||
let ac = fs::read_to_string(file).unwrap();
|
||||
let ac: Vec<ScryfallCard> = serde_json::from_str(&ac).unwrap();
|
||||
pub fn get_all_mtg_words() -> Vec<String> {
|
||||
let sqlite_file = get_local_data_sqlite_file();
|
||||
let mut conn = rusqlite::Connection::open(sqlite_file).unwrap();
|
||||
let tx = conn.transaction().unwrap();
|
||||
for card in ac {
|
||||
for word in card.name.split_whitespace() {
|
||||
let word = deunicode(word);
|
||||
let res = tx.execute(
|
||||
"INSERT INTO magic_words (word) VALUES (?1)
|
||||
ON CONFLICT (word) DO NOTHING;",
|
||||
[word.replace(",", "")],
|
||||
);
|
||||
}
|
||||
let lowercase_name = deunicode(&card.name.to_lowercase());
|
||||
let power_toughness = match card.power {
|
||||
Some(p) => Some(format!("{}/{}", p, card.toughness.unwrap())),
|
||||
None => None,
|
||||
};
|
||||
let oracle_text = match card.oracle_text {
|
||||
Some(ot) => ot,
|
||||
None => "<No Oracle Text>".to_string(),
|
||||
};
|
||||
let loyalty = match card.loyalty {
|
||||
Some(loy) => Some(loy),
|
||||
None => None,
|
||||
};
|
||||
let mana_cost = match card.mana_cost {
|
||||
Some(mc) => Some(mc),
|
||||
None => None,
|
||||
};
|
||||
let res = tx.execute(
|
||||
"INSERT INTO cards (name, lowercase_name, type_line, oracle_text, power_toughness, loyalty, mana_cost, scryfall_uri) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
|
||||
rusqlite::params![card.name, lowercase_name, card.type_line, oracle_text, power_toughness, loyalty, mana_cost, card.scryfall_uri],
|
||||
);
|
||||
let conn = rusqlite::Connection::open(sqlite_file).unwrap();
|
||||
let mut stmt = conn.prepare("SELECT word FROM mtg_words;").unwrap();
|
||||
let mut rows = stmt.query([]).unwrap();
|
||||
let mut card_names = Vec::new();
|
||||
while let Some(row) = rows.next().unwrap() {
|
||||
card_names.push(row.get(0).unwrap());
|
||||
}
|
||||
tx.commit();
|
||||
true
|
||||
card_names
|
||||
}
|
||||
|
||||
// unsure if this should be in this file...
|
||||
|
||||
impl fmt::Display for DbCard {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match &self.mana_cost {
|
||||
@@ -172,7 +142,6 @@ pub fn find_matching_cards_scryfall_style(search_strings: &Vec<String>) -> Vec<D
|
||||
sql.pop();
|
||||
sql.pop();
|
||||
sql.pop();
|
||||
dbg!(&sql);
|
||||
let mut stmt = conn.prepare(&sql).unwrap();
|
||||
stmt.query_map(rusqlite::params_from_iter(percentaged_string), |row| {
|
||||
Ok(DbCard {
|
||||
@@ -234,7 +203,7 @@ CREATE TABLE cards (
|
||||
)";
|
||||
|
||||
const CREATE_MAGIC_WORDS_TABLE_SQL: &str = "
|
||||
CREATE TABLE magic_words (
|
||||
CREATE TABLE mtg_words (
|
||||
word TEXT NOT NULL UNIQUE
|
||||
)";
|
||||
|
||||
@@ -254,3 +223,44 @@ pub fn init_db() -> bool {
|
||||
.unwrap();
|
||||
true
|
||||
}
|
||||
|
||||
pub fn update_db_with_file(file: PathBuf) -> bool {
|
||||
let ac = fs::read_to_string(file).unwrap();
|
||||
let ac: Vec<ScryfallCard> = serde_json::from_str(&ac).unwrap();
|
||||
let sqlite_file = get_local_data_sqlite_file();
|
||||
let mut conn = rusqlite::Connection::open(sqlite_file).unwrap();
|
||||
let tx = conn.transaction().unwrap();
|
||||
for card in ac {
|
||||
for word in card.name.split_whitespace() {
|
||||
let word = deunicode(&word.to_lowercase());
|
||||
let res = tx.execute(
|
||||
"INSERT INTO mtg_words (word) VALUES (?1)
|
||||
ON CONFLICT (word) DO NOTHING;",
|
||||
[word.replace(",", "")],
|
||||
);
|
||||
}
|
||||
let lowercase_name = deunicode(&card.name.to_lowercase());
|
||||
let power_toughness = match card.power {
|
||||
Some(p) => Some(format!("{}/{}", p, card.toughness.unwrap())),
|
||||
None => None,
|
||||
};
|
||||
let oracle_text = match card.oracle_text {
|
||||
Some(ot) => ot,
|
||||
None => "<No Oracle Text>".to_string(),
|
||||
};
|
||||
let loyalty = match card.loyalty {
|
||||
Some(loy) => Some(loy),
|
||||
None => None,
|
||||
};
|
||||
let mana_cost = match card.mana_cost {
|
||||
Some(mc) => Some(mc),
|
||||
None => None,
|
||||
};
|
||||
let res = tx.execute(
|
||||
"INSERT INTO cards (name, lowercase_name, type_line, oracle_text, power_toughness, loyalty, mana_cost, scryfall_uri) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
|
||||
rusqlite::params![card.name, lowercase_name, card.type_line, oracle_text, power_toughness, loyalty, mana_cost, card.scryfall_uri],
|
||||
);
|
||||
}
|
||||
tx.commit();
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user