Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
fix: name dupes
Browse files Browse the repository at this point in the history
  • Loading branch information
ZTL-UwU committed Dec 23, 2023
1 parent a0986da commit e2182bf
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Rocket.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 6 additions & 2 deletions api/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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 });
}
}

Expand Down
1 change: 1 addition & 0 deletions entity/src/paper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
version = "0.12.10"
features = [
"runtime-tokio-native-tls",
"sqlx-sqlite",
"sqlx-mysql",
]
2 changes: 1 addition & 1 deletion migration/src/m20231223_000001_create_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
2 changes: 1 addition & 1 deletion service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ serde_json = { version = "1" }
version = "0.12.10"
features = [
"runtime-tokio-native-tls",
"sqlx-sqlite",
"sqlx-mysql",
]

[dev-dependencies]
Expand Down

0 comments on commit e2182bf

Please sign in to comment.