sqlite with full text search doesn't find results when space in query

妖精的绣舞 提交于 2019-12-11 05:53:31

问题


I'm playing with notmuch-abook which uses sqlite3 to store names and email addresses. The sqlite table uses full text search, being created by:

CREATE VIRTUAL TABLE AddressBook USING fts4(Name, Address);

I have entries for myself with names "Hamish", "Hamish D" and "Hamish Downer". The query

select * from addressbook where addressbook match 'hamish';

Finds them all. However

select * from addressbook where addressbook match 'hamish d';

Finds only the entries with the exact name "Hamish D" but does not find the entries with name "Hamish Downer". I can get what I expect with:

select * from addressbook where name like 'hamish d%';

But I'd like to use the match version to match across both columns. Any idea what's going on here? Or how to get match to work as I want?


回答1:


Read the documentation.

The query

... addressbook match 'hamish d'

finds records that containt the two words hamish and d. You probably want to search for the phrase hamish d instead, which you can do with

... addressbook match '"hamish d"'

To search for prefixes, use *:

... addressbook match '"hamish d*"'


来源:https://stackoverflow.com/questions/16137070/sqlite-with-full-text-search-doesnt-find-results-when-space-in-query

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