From ab43295b29de94f86ad0858d4e454736c92b29c3 Mon Sep 17 00:00:00 2001 From: Bad Manners Date: Tue, 22 Apr 2025 19:55:48 -0300 Subject: [PATCH] Improved tag searching --- README.md | 2 +- src/views.rs | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8044983..2600d38 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ Still very much an early WIP. - [ ] Display thumbnails on post selection - [ ] Text media +- [ ] Testing - [ ] Improve CSS - [ ] User management -- [ ] Testing - [ ] Lossless compression - [ ] Migrate to Cot...? diff --git a/src/views.rs b/src/views.rs index 6f574c4..e41430a 100644 --- a/src/views.rs +++ b/src/views.rs @@ -18,7 +18,7 @@ use chrono::Utc; use image::{GenericImageView, ImageFormat, ImageReader}; use itertools::Itertools; use rand::Rng; -use samey_migration::{Expr, OnConflict, Query as MigrationQuery}; +use samey_migration::{OnConflict, Query as MigrationQuery}; use sea_orm::{ ActiveValue::Set, ColumnTrait, Condition, EntityTrait, FromQueryResult, IntoSimpleExpr, ModelTrait, PaginatorTrait, QueryFilter, QuerySelect, @@ -552,10 +552,17 @@ pub(crate) async fn search_tags( .collect() } else { SameyTag::find() - .filter(Expr::cust_with_expr( - "LOWER(\"samey_tag\".\"name\") LIKE CONCAT(?, '%')", - stripped_tag.to_lowercase(), - )) + .filter( + Condition::any() + .add( + samey_tag::Column::NormalizedName + .starts_with(stripped_tag.to_lowercase()), + ) + .add( + samey_tag::Column::NormalizedName + .contains(format!(":{}", stripped_tag.to_lowercase())), + ), + ) .limit(10) .all(&db) .await? @@ -586,10 +593,14 @@ pub(crate) async fn search_tags( .collect() } else { SameyTag::find() - .filter(Expr::cust_with_expr( - "LOWER(\"samey_tag\".\"name\") LIKE CONCAT(?, '%')", - tag.to_lowercase(), - )) + .filter( + Condition::any() + .add(samey_tag::Column::NormalizedName.starts_with(tag.to_lowercase())) + .add( + samey_tag::Column::NormalizedName + .contains(format!(":{}", tag.to_lowercase())), + ), + ) .limit(10) .all(&db) .await?