source::person::{Person, PersonForm},
traits::Crud,
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl, *};
+use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
use url::Url;
mod safe_type {
person
.filter(deleted.eq(false))
.filter(local.eq(true))
- .filter(name.ilike(from_name))
+ .filter(name.eq(from_name))
.first::<Person>(conn)
}
}
pub fn fuzzy_search(q: &str) -> String {
- let replaced = q.replace(" ", "%");
+ let replaced = q.replace("%", "\\%").replace("_", "\\_").replace(" ", "%");
format!("%{}%", replaced)
}
#[test]
fn test_fuzzy_search() {
- let test = "This is a fuzzy search";
- assert_eq!(fuzzy_search(test), "%This%is%a%fuzzy%search%".to_string());
+ let test = "This %is% _a_ fuzzy search";
+ assert_eq!(
+ fuzzy_search(test),
+ "%This%\\%is\\%%\\_a\\_%fuzzy%search%".to_string()
+ );
}
#[test]