From d53a93fd4ccea54917c53c13d7ca4b332edf8f00 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Fri, 2 Feb 2024 13:22:32 +0800 Subject: [PATCH] Fix the issue of search not working with spaces in them (rust-lang#8052) --- src/controllers/krate/search.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/controllers/krate/search.rs b/src/controllers/krate/search.rs index 197bbed7822..afcdba826a9 100644 --- a/src/controllers/krate/search.rs +++ b/src/controllers/krate/search.rs @@ -2,7 +2,7 @@ use crate::auth::AuthCheck; use diesel::dsl::*; -use diesel::sql_types::Array; +use diesel::sql_types::{Array, Text}; use diesel_full_text_search::*; use indexmap::IndexMap; use once_cell::sync::OnceCell; @@ -98,10 +98,9 @@ pub async fn search(app: AppState, req: Parts) -> AppResult> { query = query.order(Crate::with_name(q_string).desc()); if sort == "relevance" { - let q = to_tsquery_with_search_config( - configuration::TsConfigurationByName("english"), - q_string, - ); + let q = sql::("plainto_tsquery('english', ") + .bind::(q_string) + .sql(")"); let rank = ts_rank_cd(crates::textsearchable_index_col, q); query = query.then_order_by(rank.desc()) } @@ -305,15 +304,13 @@ impl<'a> FilterParams<'a> { req: &Parts, conn: &mut PgConnection, ) -> AppResult> { - use diesel::sql_types::Text; let mut query = crates::table.into_boxed(); if let Some(q_string) = self.q_string { if !q_string.is_empty() { - let q = to_tsquery_with_search_config( - configuration::TsConfigurationByName("english"), - q_string, - ); + let q = sql::("plainto_tsquery('english', ") + .bind::(q_string) + .sql(")"); query = query.filter( q.matches(crates::textsearchable_index_col) .or(Crate::loosly_matches_name(q_string)),