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