以(后缀)结尾,并包含在SQLite FTS中使用MATCH进行的字符串搜索 [英] ends with (suffix) and contains string search using MATCH in SQLite FTS

查看:168
本文介绍了以(后缀)结尾,并包含在SQLite FTS中使用MATCH进行的字符串搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的iOS应用程序中使用SQLite FTS扩展. 它的效果不错,但问题是它仅匹配字符串前缀(或以关键字搜索开头).

I am using SQLite FTS extension in my iOS application. It performs well but the problem is that it matches only string prefixes (or starts with keyword search).

这有效:

SELECT FROM tablename WHERE columnname MATCH 'searchterm*'

但以下两个没有:

SELECT FROM tablename WHERE columnname MATCH '*searchterm'


SELECT FROM tablename WHERE columnname MATCH '\*searchterm\*'

对此是否有任何变通方法或使用FTS来构建类似于LIKE '%searchterm%'查询的查询的方法.

Is there any workaround for this or any way to use FTS to build a query similar to LIKE '%searchterm%' query.

正如Retterdesdialogs指出的那样,以相反的顺序存储整个文本并在反向字符串上运行前缀搜索是解决带尾缀搜索问题(这是我最初的问题)的可能解决方案,但不适用于包含"搜索.我已经相应地更新了问题.

As pointed out by Retterdesdialogs, storing the entire text in reverse order and running a prefix search on a reverse string is a possible solution for ends with/suffix search problem, which was my original question, but it won't work for 'contains' search. I have updated the question accordingly.

推荐答案

在我的iOS和Android应用程序中,由于缺少后缀查询,其不支持子字符串匹配的原因,我避开了FTS搜索.

In my iOS and Android applications, I have shied away from FTS search for exactly the reason that it doesn't support substring matches due to lack of suffix queries.

解决方法似乎很复杂.

我求助于使用LIKE查询,该查询虽然性能不如MATCH,但可以满足我的需求.

I have resorted to using LIKE queries, which while being less performant than MATCH, served my needs.

这篇关于以(后缀)结尾,并包含在SQLite FTS中使用MATCH进行的字符串搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆