在sqlite中搜索字段中每个单词的匹配前缀 [英] Search matching prefix of every word in field in sqlite

查看:259
本文介绍了在sqlite中搜索字段中每个单词的匹配前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写SELECT语句以选择行,其中某些字段中任何单词的前缀都与给定模式匹配.我正在使用sqlite,但这是一个普遍的问题.
我提出了两个想法:

I need to write SELECT statement selecting rows, where prefix of any word from some field matches given pattern. I'm using sqlite, but it's kind of general question.
I came up with two ideas:

SELECT (...) FROM table WHERE field LIKE 'phrase%' OR field LIKE '% phrase%'

SELECT (...) FROM table WHERE ' ' || field LIKE '% phrase%'

两者看起来都不那么优雅,当我在一个SELECT中使用更多的... OR ... LIKE ...时,这会降低查询性能.

有办法更好地解决这个问题吗?

Both look not-so-elegant and when I use more ... OR ... LIKE ... in one SELECT it kills query performance.

Is there a way to handle this better?

推荐答案

一个选项是使用全文本模块". http://www.sqlite.org/fts3.html

One option is to use the The Full Text Modules; http://www.sqlite.org/fts3.html

SELECT * FROM table WHERE field MATCH 'phrase*';

这篇关于在sqlite中搜索字段中每个单词的匹配前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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