Exact phrase first before anything else in SQLite FTS?

浪子不回头ぞ 提交于 2019-12-04 16:03:57

You have to do all FTS processing (including snippet()) on the FTS table itself, and only afterwards combine the result in the uppermost query:

SELECT docid,
       snippet,
       MIN(rank) AS rank
FROM (SELECT docid,
             snippet(fts) AS snippet,
             1 AS rank
      FROM fts
      WHERE body MATCH '"what is"'
      UNION ALL
      SELECT docid,
             snippet(fts),
             2
      FROM fts
      WHERE body MATCH 'what* NEAR/3 is*')
GROUP BY docid
ORDER BY MIN(rank) /*, docid*/;

Alternatively, get all possible rows with the more general pattern, and check for the more strict MATCH in the ORDER BY:

SELECT snippet(fts)
FROM fts
WHERE body MATCH 'what* NEAR/3 is*'
ORDER BY NOT (body MATCH '"what is"');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!