pub fn escape_fts5(query: &str) -> StringExpand description
Escape FTS5 special characters in a query string
FTS5 queries support advanced syntax (AND, OR, NOT, *, #, “phrase search”, etc.). To safely search user input as literal text, we:
- Escape any double quotes by doubling them (
"->"") - Wrap the entire query in double quotes for literal phrase search
This prevents special characters like #, *, +, -, etc. from being
interpreted as FTS5 syntax operators.
§Arguments
query- The query string to escape
§Returns
The query string wrapped in double quotes with internal quotes escaped
§Example
ⓘ
use crate::search::escape_fts5;
let escaped = escape_fts5("user \"admin\" role");
assert_eq!(escaped, "\"user \"\"admin\"\" role\"");
let escaped = escape_fts5("#123");
assert_eq!(escaped, "\"#123\"");