diff --git a/src-core/src/db/search.rs b/src-core/src/db/search.rs index 202df50..4eccd1c 100644 --- a/src-core/src/db/search.rs +++ b/src-core/src/db/search.rs @@ -1,6 +1,6 @@ use std::collections::HashSet; -use rusqlite::{Connection, params}; +use rusqlite::{Connection, Transaction, params}; use wana_kana::utils::katakana_to_hiragana; use crate::{ @@ -22,8 +22,14 @@ impl<'a> SearchDatabase<'a> { Self { conn } } - pub fn create_schema(&self) -> Result<(), CJDicError> { - self.conn.execute_batch( + pub fn create_schema(&mut self) -> Result<(), CJDicError> { + let tx = self.conn.transaction()?; + SearchDatabase::create_schema_tx(&tx)?; + Ok(()) + } + + fn create_schema_tx(tx: &'a Transaction) -> Result<(), CJDicError> { + tx.execute_batch( &format!(" CREATE TABLE IF NOT EXISTS {0}.terms ( id INTEGER PRIMARY KEY, -- yomitan.terms.id OR yomitan dups OR -user.terms.id @@ -47,19 +53,6 @@ impl<'a> SearchDatabase<'a> { Ok(()) } - pub fn reset_db(&self) -> Result<(), CJDicError> { - self.conn.execute_batch(&format!( - " - DELETE FROM {0}.terms; - DROP TABLE {0}.terms_ft; - ", - DBSCHEMA[DbChild::Search] - ))?; - self.create_schema()?; - - Ok(()) - } - pub fn regenerate_yomitan( &mut self, yomitan_schema: &str, @@ -88,6 +81,16 @@ impl<'a> SearchDatabase<'a> { let tx = self.conn.transaction()?; { + tx.execute_batch(&format!( + " + DELETE FROM {0}.terms; + DROP TABLE {0}.terms_ft; + ", + DBSCHEMA[DbChild::Search] + ))?; + + SearchDatabase::create_schema_tx(&tx)?; + let mut stmt = tx.prepare(&format!( "SELECT t.id, t.term, t.reading, tr.max_score FROM {0}.terms t diff --git a/src-core/src/db/yomitan_writer.rs b/src-core/src/db/yomitan_writer.rs index e17ebc7..e2914ce 100644 --- a/src-core/src/db/yomitan_writer.rs +++ b/src-core/src/db/yomitan_writer.rs @@ -813,7 +813,6 @@ impl YomitanWriter { let mut search_db = SearchDatabase::new(&mut self.conn); search_db.create_schema()?; - search_db.reset_db()?; search_db.regenerate_yomitan("main", tokenizer.clone(), &progress_callback)?; Ok(()) diff --git a/src-core/src/tokenizer.rs b/src-core/src/tokenizer.rs index b63b1b2..64e760c 100644 --- a/src-core/src/tokenizer.rs +++ b/src-core/src/tokenizer.rs @@ -7,6 +7,7 @@ use crate::CJDicError; #[derive(Debug, Serialize)] pub struct TokenizeSegment { pub surface: String, + /// ```txt /// 0 品詞 Part-of-speech /// 1 品詞細分類1 Part-of-speech subcategory 1 /// 2 品詞細分類2 Part-of-speech subcategory 2 @@ -16,6 +17,7 @@ pub struct TokenizeSegment { /// 6 原形 Base form /// 7 読み Reading /// 8 発音 Pronunciation + /// ``` /// @see https://lindera.github.io/lindera/dictionaries/ipadic.html pub details: Vec, } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 4f7bb18..0bc9416 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "cjdic2", - "version": "0.1.0", + "version": "0.1.1", "identifier": "cc.polv.cjdic2", "build": { "beforeDevCommand": "pnpm dev",