SQLite fts3: search for a string in a column

谁说我不能喝 提交于 2019-11-28 08:16:01

问题


Is there any way to search for a particular string in a column?

I want to search like SELECT * from email_fts WHERE email_fts MATCH 'to:"a@b.com" OR from:"c@d.com"'

Thanks in advance,

Manoj


回答1:


Make sure you create proper FTS columns in the FTS index:

CREATE VIRTUAL TABLE email_fts USING fts3(subject, body, "to", "from");

And then you can search individual FTS columns:

SELECT  rowid 
FROM    email_fts 
WHERE   "to" MATCH 'a@b.com'

UNION

SELECT  rowid 
FROM    email_fts 
WHERE   "from" MATCH 'c@d.com'

EDIT: My previous answer had an OR in the WHERE clause. Apparently sqlite doesn't support combining OR queries with MATCH conditions. The above union works.

FTS docs are here, this is one of the examples used in the docs.

http://sqlite.org/fts3.html



来源:https://stackoverflow.com/questions/2621308/sqlite-fts3-search-for-a-string-in-a-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!