plan search db

This commit is contained in:
polv committed 2026-03-08 19:17:31 +07:00
1 parent ec14023c04
commit a97da3fa1d
6 files changed
+61 -23

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
#[allow(unused)]
pub(super) fn normalize_reading(s: &str) -> String {
s.chars()
.map(|c| {
if c >= 'ア' && c <= 'ン' {
// Katakana range
if let Some(x) = char::from_u32(c as u32 - 0x60) {
x // Convert to Hiragana
} else {
c // Ensure it's a valid char
}
} else {
c // Return the character as is if it's not in the range
}
})
.collect()
}
+2 -2
View File
@@ -31,7 +31,7 @@ impl YomitanDatabase {
}
fn decompressor(&self) -> Result<Decompressor<'_>, CJDicError> {
let conn = self.db.conn.lock().unwrap();
let conn = self.db.conn.lock()?;
let row = conn.query_row(
"SELECT value FROM glossary.meta WHERE key = 'zstd_dict'",
@@ -79,7 +79,7 @@ impl YomitanDatabase {
let eq1 = if q_term_norm.len() > 0 { "GLOB" } else { "=" };
let eq2 = if q_reading.len() > 0 { "GLOB" } else { "=" };
let conn = self.db.conn.lock().unwrap();
let conn = self.db.conn.lock()?;
conn.execute_batch(
"
CREATE TEMP TABLE IF NOT EXISTS yomitan_lookup_keys (
+11 -7
View File
@@ -13,7 +13,7 @@ use zip::ZipArchive;
use crate::{
CJDicError, Timer,
db::{DBFILE, DbChild},
db::{DBFILE, DBSCHEMA, DbChild},
};
fn blake3_hex(s: &str) -> String {
@@ -174,7 +174,8 @@ impl YomitanWriter {
)?;
self.create_materialized_views()?;
self.attach_glossary()?;
self.attach_db(DbChild::YomitanGlossary)?;
self.attach_db(DbChild::Search)?;
let schema_version = "2026-03-07";
@@ -361,7 +362,7 @@ impl YomitanWriter {
Ok(())
}
fn attach_glossary(&mut self) -> Result<(), CJDicError> {
fn attach_db(&mut self, db_child: DbChild) -> Result<(), CJDicError> {
let dir = self.dir.clone();
let path = if self.dir.is_absolute() {
dir
@@ -369,8 +370,8 @@ impl YomitanWriter {
current_dir()?.join(dir)
};
let db_file = DBFILE[DbChild::YomitanGlossary];
let schema_name = "glossary";
let db_file = DBFILE[db_child];
let schema_name = DBSCHEMA[db_child];
let path = path.join(db_file).to_string_lossy().replace(r"\", r"/");
@@ -392,7 +393,10 @@ impl YomitanWriter {
schema_name
))?;
self.create_schema_glossary()?;
match db_child {
DbChild::YomitanGlossary => self.create_schema_glossary()?,
_ => (),
}
Ok(())
}
@@ -529,7 +533,7 @@ impl YomitanWriter {
}
}
self.attach_glossary()?;
self.attach_db(DbChild::YomitanGlossary)?;
{
let tx = self.conn.transaction()?;