我有这个表
文本
| txt_id | txt_content |
|--------+----------------------------------------------|
| 1 | A ton of text and <<this>> |
| 2 | More text <<and>> that |
| 3 | <<Very>> much <<text>> enough for<everyone>> |
And this table
标记
| tag_id | tag_name |
|--------+----------|
| 1 | THIS |
| 2 | AND |
| 3 | VERY |
| 4 | TEXT |
| 5 | EVERYONE |
我需要一个查询来生成这个表。
| txt_id | tag_id |
|--------+--------|
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 3 | 4 |
| 3 | 5 |
通过单独获取每段文本来处理python代码是很重要的,但是文本表有许多行(>30M),我认为这将是在数据库后端通信上花费太多时间。有一种方法来做这种事情与MySQL吗?我甚至会满足于
| txt_id | tag_id |
|--------+----------|
| 1 | this |
| 2 | and |
| 3 | Very |
| 3 | text |
| 3 | everyone |
但是我希望最后一部分在MySQL中很容易做到
这不需要特别快,但它会做你想要的:
select t.txt_id, ta.tag_id
from text t join
tags ta
on t.txt_content like concat('%<', ta.tag_name, '>%');