From 59c11897b27da746f7177d4d1df4a59407a69fd1 Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Tue, 24 Oct 2017 21:54:27 +0200 Subject: [PATCH] Tweak FTS query Attempt to smartly use NEAR searches and prefix searches depending on input. This is hopefully a good idea --- src/state.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/state.rs b/src/state.rs index 5427ec2..3a7e76d 100644 --- a/src/state.rs +++ b/src/state.rs @@ -316,7 +316,18 @@ impl State { format!("\"{}\"", src.replace('\"', "\"\"")) } - let query = fts_quote(&query_string); + let words = query_string + .split_whitespace() + .map(fts_quote) + .collect::>(); + + let query = if words.len() > 1 { + format!("NEAR({})", words.join(" ")) + } else if words.len() == 1 { + format!("{}*", words[0]) + } else { + "\"\"".to_owned() + }; Ok( sql::<(Text, Text, Text)>(