MYSQL如何在一个句子中匹配两个单词 [英] MYSQL How to match two words in a sentence

查看:124
本文介绍了MYSQL如何在一个句子中匹配两个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,该表的mytext列包含句子.

I have a table with column mytext which contains sentences.

我想搜索包含两个单词(例如我的",学校")的任意顺序的句子.

I want to search sentences which are having two words like "my" "school" in any order.

我想要的结果是

  1. 牛津是我的学校

  1. oxford is my school

我的名字是kk学校是jes

my name is kk school is jes

推荐答案

如果您正在使用InnoDB表(并且您可能正在使用),则可以使用LIKE语句:

If you're using InnoDB tables(and you probably are), you can use LIKE statement:

SELECT * FROM mytable WHERE mycolumn LIKE "%my%" OR mycolumn LIKE "%school%";

SELECT * FROM mytable WHERE mycolumn LIKE "%my%" OR mycolumn LIKE "%school%";

对于全文搜索,更好的解决方案是使用专用的搜索引擎,并为此进行了优化-例如 elasticsearch

For fulltext search much better solution would be using dedicated search engine, optimized for such purposes - for example elasticsearch.

这篇关于MYSQL如何在一个句子中匹配两个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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