Tweak FTS query

Attempt to smartly use NEAR searches and prefix searches depending on input. This is hopefully a good idea
This commit is contained in:
Magnus Hoff 2017-10-24 21:54:27 +02:00
parent 8104430701
commit 59c11897b2

View file

@ -316,7 +316,18 @@ impl State {
format!("\"{}\"", src.replace('\"', "\"\"")) format!("\"{}\"", src.replace('\"', "\"\""))
} }
let query = fts_quote(&query_string); let words = query_string
.split_whitespace()
.map(fts_quote)
.collect::<Vec<_>>();
let query = if words.len() > 1 {
format!("NEAR({})", words.join(" "))
} else if words.len() == 1 {
format!("{}*", words[0])
} else {
"\"\"".to_owned()
};
Ok( Ok(
sql::<(Text, Text, Text)>( sql::<(Text, Text, Text)>(