Mysql - 从指定文本中选择单词
我有一个包含 413,000 个地点名称(Pris、伦敦...)的表,有没有办法(查询)从指定文本中选择位置。
例如:
“伦敦交通局 (TfL) 正在与美国、澳大利亚和欧洲合作伙伴就为巴黎、纽约发行单一非接触式卡进行谈判”。
我想要一个查询:
* London
* Paris
* New York
我尝试过
SELECT name
FROM coutries
WHERE ("Transport for London (TfL) is in talks with its American, Australian and European partners about issuing a single contactless card for Paris, New York") LIKE CONCAT('%', name, '%');
它很慢并且没有给出确切的单词,例如(巴黎,纽约,欧元,约克...)
我怎样才能获得确切的单词?
I have a table contains 413,000 places name (Pris, London,...) is there a way (query) to select locations from specified text.
for example:
" Transport for London (TfL) is in talks with its American, Australian and European partners about issuing a single contactless card for Paris, New York".
I want a query to get:
* London
* Paris
* New York
I tried
SELECT name
FROM coutries
WHERE ("Transport for London (TfL) is in talks with its American, Australian and European partners about issuing a single contactless card for Paris, New York") LIKE CONCAT('%', name, '%');
it's slow and don't give the exact word like (Paris, New York, Euro, York ...)
How can I get exact the exact word ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你最好在前端/中端代码上将句子分成单词,然后执行类似
e.tc 的 操作
这样它将(尝试)使用索引(如果有)作为名称。
You'd better split up your sentence into words on your front/middle-end code, and do something like
e.t.c
This way it will (try to) use indexes (if any) for name.
你需要的是mysql全文搜索。
这应该有效:
What you need is the mysql fulltext search.
This should work:
执行这样的查询很奇怪,您不能更改表的结构以匹配更简单的数据吗?
It's weird to have such query to perform, can't you change your table's structure to match simpler data ?
以相反的方式进行:
选择 *
来自国家
where text like '%place1%' or like '%place2%'...
使用 for 或 while 构建 SQL,这只是几个可行选项之一。
Do it the opposite way:
select *
from countries
where text like '%place1%' or like '%place2%'...
Build the SQL with a for or while, just one of several feasible options.