-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Escaping FTS search strings #246
Comments
This is a smart feature. I have something that does this in Datasette, extracting it out to |
I have found a similar problem, but I only when using that type of query (with ... MATCH '"one two thr" * '
... MATCH 'one + two + thr*' I thought I could build a query like the first one using this function: def prefix(query: str):
return f'"{query}" *' And then I use the output of that function as the query parameter for the standard However, my use case is different because I'm the one "deciding" when to use a prefix search, not the end user. I also haven't done many tests, but maybe you found that useful. One thing I could think of is checking if the query has an This is just for prefix queries, I think having the escaping function is still useful for other use cases. |
The I'll be adding further improvements relating to this (a |
Thanks for the excellent library, it's very nice to use!
I've been building some in memory search functionality for a data annotation tool i'm making, and I got tripped up a little bit with escaping the full text search queries. First I tried using
db.quote(q)
, which doesn't work, because sqlite FTS has it's own (separate) query syntax. You can see this happening here also:http://search-24ways.herokuapp.com/24ways-f8f455f/articles?_search=acces%2A
I got around this by aggressively escaping quotes inside the query string like this:
This works in the sense it doesn't crash, but it also removes access to the search query syntax. Given the well specified definition, it might be possible for sqlite-utils to provide a
db.quote_query(q)
which would intelligently escape a query whilst leaving the syntax intact. This would be very nice!The text was updated successfully, but these errors were encountered: