use GLOB, not LIKE

This commit is contained in:
polv committed 2026-02-22 12:57:45 +07:00
1 parent 8330a78c12
commit 707c4274d1
3 files changed
+38 -22

No files matched your search

+8 -1
View File
@@ -1,6 +1,7 @@
use std::{ use std::{
fs::read_dir, fs::read_dir,
path::{Path, absolute}, path::{Path, absolute},
time::Instant,
}; };
use anyhow::{Context, Ok}; use anyhow::{Context, Ok};
@@ -19,8 +20,14 @@ fn main() -> Result<(), anyhow::Error> {
let p = e.path(); let p = e.path();
if p.extension().and_then(|s| s.to_str()) == Some("zip") { if p.extension().and_then(|s| s.to_str()) == Some("zip") {
let start = Instant::now();
println!("zip_file: {:?}", p); println!("zip_file: {:?}", p);
println!("{:?}", import_bundled_zip_file(conn, p)?); println!(
"{:?}\n[{:.2?}]",
import_bundled_zip_file(conn, p)?,
start.elapsed(),
);
} else { } else {
println!("not zip_file: {:?}", p); println!("not zip_file: {:?}", p);
} }
+5 -1
View File
@@ -1,11 +1,15 @@
use std::time::Instant;
use anyhow::Ok; use anyhow::Ok;
use cjdic2_core::db::search_yomitan; use cjdic2_core::db::search_yomitan;
use rusqlite::Connection; use rusqlite::Connection;
fn main() -> Result<(), anyhow::Error> { fn main() -> Result<(), anyhow::Error> {
let conn = &mut Connection::open("test.db")?; let conn = &mut Connection::open("test.db")?;
let start = Instant::now();
let rs = search_yomitan(conn, "食べる", "食べる", 5, 0)?; let rs = search_yomitan(conn, "食べる", "食べる", 5, 0)?;
println!("{:#?}", rs); println!("{:#?}\n[{:.2?}]", rs, start.elapsed());
Ok(()) Ok(())
} }
+25 -20
View File
@@ -57,6 +57,10 @@ fn create_schema(conn: &Connection) -> rusqlite::Result<()> {
sequence INTEGER, sequence INTEGER,
term_tags_id INTEGER term_tags_id INTEGER
); );
CREATE INDEX IF NOT EXISTS terms_term_reading ON terms (term, reading);
CREATE INDEX IF NOT EXISTS terms_term ON terms (term);
CREATE INDEX IF NOT EXISTS terms_reading ON terms (reading);
CREATE TABLE IF NOT EXISTS term_meta ( CREATE TABLE IF NOT EXISTS term_meta (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
dict_id INTEGER NOT NULL REFERENCES dictionaries(id) ON DELETE CASCADE, dict_id INTEGER NOT NULL REFERENCES dictionaries(id) ON DELETE CASCADE,
@@ -396,28 +400,29 @@ pub fn search_yomitan(
) -> Result<Vec<YomitanRow>, CJDicError> { ) -> Result<Vec<YomitanRow>, CJDicError> {
let and_or = if q_term == q_reading { "OR" } else { "AND" }; let and_or = if q_term == q_reading { "OR" } else { "AND" };
// TODO: consider using = if not GLOB string
let sql = format!( let sql = format!(
r#" r#"
SELECT SELECT
t.term, t.term,
t.reading, t.reading,
COALESCE(dt.tags, '') AS def_tags, COALESCE(dt.tags, '') AS def_tags,
COALESCE(r.rules, '') AS rules, COALESCE(r.rules, '') AS rules,
t.score, t.score,
g.content AS glossary_json, g.content AS glossary_json,
t.sequence, t.sequence,
COALESCE(tt.tags, '') AS term_tags, COALESCE(tt.tags, '') AS term_tags,
d.title AS dict_title d.title AS dict_title
FROM terms t FROM terms t
JOIN glossaries g ON g.id = t.glossary_id JOIN glossaries g ON g.id = t.glossary_id
JOIN dictionaries d ON d.id = t.dict_id JOIN dictionaries d ON d.id = t.dict_id
LEFT JOIN def_tag_sets dt ON dt.id = t.def_tags_id LEFT JOIN def_tag_sets dt ON dt.id = t.def_tags_id
LEFT JOIN rule_sets r ON r.id = t.rules_id LEFT JOIN rule_sets r ON r.id = t.rules_id
LEFT JOIN term_tag_sets tt ON tt.id = t.term_tags_id LEFT JOIN term_tag_sets tt ON tt.id = t.term_tags_id
WHERE t.term LIKE ?1 ESCAPE '\' {} t.reading LIKE ?2 ESCAPE '\' WHERE t.term GLOB ?1 {} t.reading GLOB ?2
ORDER BY t.score DESC ORDER BY t.score DESC
LIMIT ?3 OFFSET ?4 LIMIT ?3 OFFSET ?4
"#, "#,
and_or and_or
); );