简体   繁体   English

在mysql <5.6.4中搜索单词而不是短语

[英]Searching for words, not a phrase in mysql < 5.6.4

I'm looking for a way to search words in mysql table. 我正在寻找一种在mysql表中搜索单词的方法。 Considering I have a table like this: 考虑到我有一个这样的表:

CREATE TABLE IF NOT EXISTS `q_news` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(250) NOT NULL,
  `short_content` text NOT NULL,
  `content` text NOT NULL,
  `description` varchar(400) NOT NULL,
  `keywords` varchar(100) NOT NULL,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ;

And in one of the records, in title field I have "The quick brown fox jumps over the lazy dog" 在其中一项记录中, title字段中有“快速的棕色狐狸跳过懒狗”

Now, I want to get this record, when looking for "quick lazy" - I can't use match against, because it's innoDb and mysql version is below 5.6.4. 现在,当我寻找“快速懒惰”时,我想获得此记录-我不能使用match,因为它是innoDb并且mysql版本低于5.6.4。 What's the solution then? 那有什么解决方案呢? The only thing which comes to my mind is : 我唯一想到的是:

select * from q_news where `title` like '%quick%%lazy%'

But somehow I don't like this solution, is there a better way? 但是以某种方式我不喜欢这种解决方案,有更好的方法吗?

ps. ps。 I didn't know how to phrase my question, so couldn't google it, sorry if this is duplicate. 我不知道该如何表达我的问题,所以无法搜索它,对不起,如果有重复的话。

How about this? 这个怎么样?

SELECT * FROM q_news WHERE `title` LIKE '%quick%' AND `title` LIKE '%lazy%'

Using 2 LIKE can solve your problem. 使用2 LIKE可以解决您的问题。

尝试这个:

SELECT * FROM q_news WHERE MATCH(title) AGAINST ('quick lazy');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM