简体   繁体   English

最好的方法在MySQL中为一个别有用心的“喜欢%”请求存储多个值?

[英]Best way to store multiple values in MySQL for an ulterior “like %” request?

I am running a website with classified ads and I'd like to set up a function which will send an email alert when a new ad matches some patterns. 我正在运行一个带有分类广告的网站,我想设置一个功能,当新广告与某些模式匹配时,该功能将发送电子邮件警报。

The idea is to allow the users to store multiples patterns, then perform a SELECT with them: 这个想法是允许用户存储倍数模式,然后对他们执行SELECT:

select ad from table where (content LIKE '%this%' OR content LIKE '%that%')

Of course, I don't know in advance how many patterns the user will need. 当然,我事先不知道用户需要多少个模式。

One solution would be to create one line per user and per pattern, and selecting with joining the tables, but I am afraid of the database performance. 一种解决方案是为每个用户和每个模式创建一行,并通过连接表进行选择,但是我担心数据库的性能。

I've thought about JSON data but I can't figure out how to do something like that: 我已经考虑过JSON数据,但是我不知道该怎么做:

select ad from table where content like (["this","that"])

Or maybe there is a better way? 还是有更好的方法?

Edit 编辑

After viewing the first answers (thank you) I realize I was not clear enough. 查看了最初的答案(谢谢)后,我意识到我还不够清楚。

The patterns will be also stored in the database, the final request should be something like: 模式也将存储在数据库中,最终请求应类似于:

select ad from table where content LIKE (select *something* from pattern_table where userId = 123)

The question is mainly : what is the best way to store the patterns in pattern_table 问题主要是:在pattern_table中存储模式的最佳方法是什么?

一旦尝试

select ad from table where content REGEXP 'this|that'

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

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