Skip to content

Commit 1935d3b

Browse files
authored
Fix the issue of relevant search not working with spaces in them while using seek pagination (#8194)
1 parent 0493372 commit 1935d3b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/controllers/krate/search.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,17 +506,16 @@ impl<'a> FilterParams<'a> {
506506
// OR (exact_match = exact_match' AND rank < rank')
507507
// OR exact_match < exact_match'`
508508
let q_string = self.q_string.expect("q_string should not be None");
509-
let q = to_tsquery_with_search_config(
510-
configuration::TsConfigurationByName("english"),
511-
q_string,
512-
);
509+
let q = sql::<TsQuery>("plainto_tsquery('english', ")
510+
.bind::<Text, _>(q_string)
511+
.sql(")");
513512
let rank = ts_rank_cd(crates::textsearchable_index_col, q);
514513
let name_exact_match = Crate::with_name(q_string);
515514
vec![
516515
Box::new(
517516
name_exact_match
518517
.eq(exact)
519-
.and(rank.eq(rank_in))
518+
.and(rank.clone().eq(rank_in))
520519
.and(crates::name.nullable().gt(crate_name_by_id(id)))
521520
.nullable(),
522521
),

src/tests/routes/crates/list.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ fn index_sorting() {
429429
}
430430

431431
// Sort by relevance
432-
for query in ["q=foo_sort", "q=sort"] {
432+
// Add query containing a space to ensure tsquery works
433+
for query in ["q=foo_sort", "q=sort", "q=foo%20sort"] {
433434
let (resp, calls) = page_with_seek(&anon, query);
434435
assert_eq!(calls, resp[0].meta.total + 1);
435436
let decoded_seeks = resp

0 commit comments

Comments
 (0)