Skip to content

Commit

Permalink
spi-stats:fix add or modify tsv pinyin.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Nov 2, 2023
1 parent 53ebbea commit b3870c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion spi/spi-search/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ serde.workspace = true
tardis = { workspace = true, features = ["reldb-postgres", "web-server", "web-client"] }
bios-basic = { path = "../../basic", features = ["default"] }
strum = { workerspace = true, features = ["derive"] }
pinyin = { version = "0.10" }

[dev-dependencies]
tardis = { workspace = true, features = ["test"] }
bios-basic = { path = "../../basic", features = ["default", "test"] }
testcontainers-modules ={ workspace = true }
testcontainers-modules ={ workspace = true }
pinyin = { version = "0.10" }
12 changes: 8 additions & 4 deletions spi/spi-search/src/serv/pg/search_pg_item_serv.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use pinyin::{Pinyin, to_pinyin_vec};
use tardis::{
basic::{dto::TardisContext, error::TardisError, result::TardisResult},
chrono::Utc,
Expand Down Expand Up @@ -29,8 +30,9 @@ pub async fn add(add_req: &mut SearchItemAddReq, _funs: &TardisFunsInst, ctx: &T
params.push(Value::from(add_req.kind.to_string()));
params.push(Value::from(add_req.key.to_string()));
params.push(Value::from(add_req.title.as_str()));
params.push(Value::from(add_req.title.as_str()));
params.push(Value::from(format!("{},{}",add_req.title.as_str(), to_pinyin_vec(add_req.title.as_str(), Pinyin::plain).join(","))));
params.push(Value::from(add_req.content.as_str()));
params.push(Value::from(format!("{},{}",add_req.content.as_str(),to_pinyin_vec(add_req.content.as_str(),Pinyin::plain).join(","))));
params.push(Value::from(add_req.owner.as_ref().unwrap_or(&"".to_string()).as_str()));
params.push(Value::from(add_req.own_paths.as_ref().unwrap_or(&"".to_string()).as_str()));
params.push(Value::from(if let Some(create_time) = add_req.create_time { create_time } else { Utc::now() }));
Expand All @@ -52,7 +54,7 @@ pub async fn add(add_req: &mut SearchItemAddReq, _funs: &TardisFunsInst, ctx: &T
r#"INSERT INTO {table_name}
(kind, key, title, title_tsv,content, content_tsv, owner, own_paths, create_time, update_time, ext, visit_keys)
VALUES
($1, $2, $3, to_tsvector('public.chinese_zh', $4), $5, to_tsvector('public.chinese_zh', $5), $6, $7, $8, $9, $10, {})"#,
($1, $2, $3, to_tsvector('public.chinese_zh', $4), $5, to_tsvector('public.chinese_zh', $6), $7, $8, $9, $10, $11, {})"#,
if add_req.visit_keys.is_some() { "$11" } else { "null" },
),
params,
Expand All @@ -77,13 +79,15 @@ pub async fn modify(tag: &str, key: &str, modify_req: &mut SearchItemModifyReq,
};
if let Some(title) = &modify_req.title {
sql_sets.push(format!("title = ${}", params.len() + 1));
sql_sets.push(format!("title_tsv = to_tsvector('public.chinese_zh', ${})", params.len() + 1));
params.push(Value::from(title));
sql_sets.push(format!("title_tsv = to_tsvector('public.chinese_zh', ${})", params.len() + 1));
params.push(Value::from(format!("{},{}",title,to_pinyin_vec(title, Pinyin::plain).join(","))));
};
if let Some(content) = &modify_req.content {
sql_sets.push(format!("content = ${}", params.len() + 1));
sql_sets.push(format!("content_tsv = to_tsvector('public.chinese_zh', ${})", params.len() + 1));
params.push(Value::from(content));
sql_sets.push(format!("content_tsv = to_tsvector('public.chinese_zh', ${})", params.len() + 1));
params.push(Value::from(format!("{},{}",content,to_pinyin_vec(content, Pinyin::plain).join(","))));
};
if let Some(owner) = &modify_req.owner {
sql_sets.push(format!("owner = ${}", params.len() + 1));
Expand Down

0 comments on commit b3870c1

Please sign in to comment.