sql - SQLite Full Text Search Queries With Hyphens -
i have been using sqlite (3) small website. recently, have discovered sqlite's full text search (fts) capability , leveraged simple search feature. however, user inadvertently discovered hyphen ('-') in search string wrong thing. seems indicate token following should excluded. in fact, when change hyphen plus or space, work.
my questions: 1) correct in analysis? read sqlite documentation regarding fts feature , found no discussion this. 2) how should mitigate this? manually replace hyphens before passing them sqlite?
a small, concrete example of i'm seeing:
sqlite> create virtual table fts_table using fts4 ...> ( content text ); sqlite> insert fts_table values ("title: f-1 race (game boy)"); sqlite> insert fts_table values ("title: f-zero (snes)"); sqlite> insert fts_table values ("title: f-15 strike eagle ii (genesis)"); sqlite> select * fts_table; title: f-1 race (game boy) title: f-zero (snes) title: f-15 strike eagle ii (genesis)
(this database related old video games, might have guessed.)
so website takes search string user , plugs select statement using match operator. search string 'f-zero', relevant sql becomes:
sqlite> select * fts_table content match 'f-zero'; title: f-1 race (game boy) title: f-15 strike eagle ii (genesis)
i.e., doesn't match title 'f-zero'. however, string 'f+zero' returns right thing:
sqlite> select * fts_table content match 'f+zero'; title: f-zero (snes)
again, suppose substitute '+' or space '-' before sending string sqlite, doesn't feel right solution.
i found in doc :
the not operator (or, if using standard syntax, unary "-" operator)
so same, , example :
-- query documents contain term "database", not contain -- term "sqlite". document 1 document matches criteria. select * docs docs match 'database not sqlite';
that's same :
select * docs docs match 'database -sqlite';
in case must use phrase queries, :
select * fts_table content match '"f-zero"';
Comments
Post a Comment