mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-09 17:39:35 +00:00
full text search and UI button
This commit is contained in:
1 parent
afacdc0856
commit
f0cafa450d
10 files changed
+189
-65
No files matched your search
+39
-1
@@ -16,6 +16,14 @@ use crate::{
|
||||
tokenizer::{TokenizeSegment, Tokenizer},
|
||||
};
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct YomitanDictEntry {
|
||||
pub title: String,
|
||||
pub bundle_name: String,
|
||||
pub revision: String,
|
||||
pub lang: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, Clone)]
|
||||
pub struct LoadYomitanZipDirResult {
|
||||
pub new_dicts: Vec<String>,
|
||||
@@ -42,8 +50,9 @@ impl AppService {
|
||||
db_dir: impl AsRef<Path>,
|
||||
vibrato_dic: impl AsRef<Path>,
|
||||
) -> Result<Self, CJDicError> {
|
||||
let db = Database::new(db_dir)?;
|
||||
let tokenizer = Tokenizer::new(vibrato_dic)?;
|
||||
let db = Database::new(db_dir, tokenizer.clone())?;
|
||||
|
||||
Ok(Self { db, tokenizer })
|
||||
}
|
||||
|
||||
@@ -125,6 +134,35 @@ impl AppService {
|
||||
Ok(writer)
|
||||
}
|
||||
|
||||
pub fn list_yomitan_dict(&self) -> Result<Vec<YomitanDictEntry>, CJDicError> {
|
||||
let db_path = self.db.dir.join(DBFILE[DbChild::Yomitan]);
|
||||
let mut out = vec![];
|
||||
|
||||
if db_path.exists() {
|
||||
let conn = Connection::open(&db_path)?;
|
||||
let mut stmt = conn.prepare(
|
||||
"
|
||||
SELECT title, bundle_name, revision, lang
|
||||
FROM dictionaries
|
||||
WHERE bundle_name IS NOT NULL",
|
||||
)?;
|
||||
let rows = stmt.query_map([], |r| {
|
||||
Ok(YomitanDictEntry {
|
||||
title: r.get(0)?,
|
||||
bundle_name: r.get(1)?,
|
||||
revision: r.get(2)?,
|
||||
lang: r.get(3)?,
|
||||
})
|
||||
})?;
|
||||
|
||||
for r in rows {
|
||||
out.push(r?);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub fn load_yomitan_zip_dir<Z, LoadCallback, ImportCallback>(
|
||||
&self,
|
||||
zip_dir: Vec<Z>,
|
||||
|
||||
Reference in new issue
Block a user