mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-09 17:39:35 +00:00
0.1.1 + transaction for reset search.db
This commit is contained in:
1 parent
a00efbf505
commit
8ee2fe950f
4 files changed
+22
-18
No files matched your search
+19
-16
@@ -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
|
||||
|
||||
@@ -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(())
|
||||
|
||||
@@ -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<String>,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user