Skip to content

Commit d53a93f

Browse files
committed
Fix the issue of search not working with spaces in them (#8052)
1 parent 179351a commit d53a93f

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/controllers/krate/search.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::auth::AuthCheck;
44
use diesel::dsl::*;
5-
use diesel::sql_types::Array;
5+
use diesel::sql_types::{Array, Text};
66
use diesel_full_text_search::*;
77
use indexmap::IndexMap;
88
use once_cell::sync::OnceCell;
@@ -98,10 +98,9 @@ pub async fn search(app: AppState, req: Parts) -> AppResult<Json<Value>> {
9898
query = query.order(Crate::with_name(q_string).desc());
9999

100100
if sort == "relevance" {
101-
let q = to_tsquery_with_search_config(
102-
configuration::TsConfigurationByName("english"),
103-
q_string,
104-
);
101+
let q = sql::<TsQuery>("plainto_tsquery('english', ")
102+
.bind::<Text, _>(q_string)
103+
.sql(")");
105104
let rank = ts_rank_cd(crates::textsearchable_index_col, q);
106105
query = query.then_order_by(rank.desc())
107106
}
@@ -305,15 +304,13 @@ impl<'a> FilterParams<'a> {
305304
req: &Parts,
306305
conn: &mut PgConnection,
307306
) -> AppResult<crates::BoxedQuery<'a, diesel::pg::Pg>> {
308-
use diesel::sql_types::Text;
309307
let mut query = crates::table.into_boxed();
310308

311309
if let Some(q_string) = self.q_string {
312310
if !q_string.is_empty() {
313-
let q = to_tsquery_with_search_config(
314-
configuration::TsConfigurationByName("english"),
315-
q_string,
316-
);
311+
let q = sql::<TsQuery>("plainto_tsquery('english', ")
312+
.bind::<Text, _>(q_string)
313+
.sql(")");
317314
query = query.filter(
318315
q.matches(crates::textsearchable_index_col)
319316
.or(Crate::loosly_matches_name(q_string)),

0 commit comments

Comments
 (0)