From e2182bf6fb91c561cfacad3ef3df4599b8f6711f Mon Sep 17 00:00:00 2001 From: ZTL-UwU Date: Sun, 24 Dec 2023 01:14:26 +0800 Subject: [PATCH] fix: name dupes --- Rocket.toml | 5 ++++- api/src/process.rs | 8 ++++++-- entity/src/paper.rs | 1 + migration/Cargo.toml | 2 +- migration/src/m20231223_000001_create_tables.rs | 2 +- service/Cargo.toml | 2 +- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Rocket.toml b/Rocket.toml index 3449e9e..7ffef2f 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -3,4 +3,7 @@ address = "0.0.0.0" [default.databases.sea_orm] # sqlite -url = "sqlite://db.sqlite?mode=rwc" +# url = "sqlite://db.sqlite?mode=rwc" + +# mysql +url = "mysql://root:@localhost/pdrs" diff --git a/api/src/process.rs b/api/src/process.rs index d043d0e..ed67435 100644 --- a/api/src/process.rs +++ b/api/src/process.rs @@ -49,16 +49,18 @@ pub async fn similarity( } pub async fn update_feature_names(sep_text: &[&str], db: &DbConn) -> Result<(), DbErr> { - let names = Query::list_names(db).await.unwrap(); + let mut names = Query::list_names(db).await.unwrap(); for word in sep_text { let mut found = false; - for name in &names { + for name in &mut names { if name.name == *word { + println!("{} {}", word, name.df); found = true; if let Err(e) = Mutation::update_name(db, &name.name, name.df + 1).await { return Err(e); } + name.df += 1; break; } } @@ -67,6 +69,8 @@ pub async fn update_feature_names(sep_text: &[&str], db: &DbConn) -> Result<(), if let Err(e) = Mutation::add_name(db, &word, 1).await { return Err(e); } + // dummy indicator to avoid the same word being added repeatedly + names.push(entity::name::Model { id: 0, name: String::from(*word), df: 1 }); } } diff --git a/entity/src/paper.rs b/entity/src/paper.rs index 1b994cf..8b7f2a4 100644 --- a/entity/src/paper.rs +++ b/entity/src/paper.rs @@ -8,6 +8,7 @@ pub struct Model { #[sea_orm(primary_key)] pub id: i32, pub pid: String, + #[sea_orm(column_type = "Text")] pub text: String, } diff --git a/migration/Cargo.toml b/migration/Cargo.toml index acfc90c..167d920 100644 --- a/migration/Cargo.toml +++ b/migration/Cargo.toml @@ -16,5 +16,5 @@ async-std = { version = "1", features = ["attributes", "tokio1"] } version = "0.12.10" features = [ "runtime-tokio-native-tls", - "sqlx-sqlite", + "sqlx-mysql", ] diff --git a/migration/src/m20231223_000001_create_tables.rs b/migration/src/m20231223_000001_create_tables.rs index c409d21..729268d 100644 --- a/migration/src/m20231223_000001_create_tables.rs +++ b/migration/src/m20231223_000001_create_tables.rs @@ -20,7 +20,7 @@ impl MigrationTrait for Migration { .primary_key(), ) .col(ColumnDef::new(Papers::Pid).string().not_null()) - .col(ColumnDef::new(Papers::Text).string().not_null()) + .col(ColumnDef::new(Papers::Text).text().not_null()) .to_owned(), ) .await?; diff --git a/service/Cargo.toml b/service/Cargo.toml index 2342540..14fe76d 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -11,7 +11,7 @@ serde_json = { version = "1" } version = "0.12.10" features = [ "runtime-tokio-native-tls", - "sqlx-sqlite", + "sqlx-mysql", ] [dev-dependencies]