Mysql - 从指定文本中选择单词

发布于 2024-09-27 02:21:16 字数 528 浏览 5 评论 0原文

我有一个包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧情别恋 2024-10-04 02:21:16

你最好在前端/中端代码上将句子分成单词,然后执行类似

SELECT name from countries where 
name in ('Transport', 'for', 'London')

e.tc 的 操作
这样它将(尝试)使用索引(如果有)作为名称。

You'd better split up your sentence into words on your front/middle-end code, and do something like

SELECT name from countries where 
name in ('Transport', 'for', 'London')

e.t.c
This way it will (try to) use indexes (if any) for name.

梦里泪两行 2024-10-04 02:21:16

你需要的是mysql全文搜索。
这应该有效:

SELECT name 
FROM coutries 
WHERE MATCH ("Transport for London (TfL) is in talks with its American, Australian and European partners about issuing a single contactless card for Paris, New York") AGAINST (name);

What you need is the mysql fulltext search.
This should work:

SELECT name 
FROM coutries 
WHERE MATCH ("Transport for London (TfL) is in talks with its American, Australian and European partners about issuing a single contactless card for Paris, New York") AGAINST (name);
时光磨忆 2024-10-04 02:21:16

执行这样的查询很奇怪,您不能更改表的结构以匹配更简单的数据吗?

It's weird to have such query to perform, can't you change your table's structure to match simpler data ?

無處可尋 2024-10-04 02:21:16

以相反的方式进行:

  1. 从原始文本中提取搜索到的字符串
  2. 创建一个简单的 SQL。

选择 *
来自国家
where text like '%place1%' or like '%place2%'...

使用 for 或 while 构建 SQL,这只是几个可行选项之一。

Do it the opposite way:

  1. Extract the rearched strings from the raw text
  2. Make a simple SQL.

select *
from countries
where text like '%place1%' or like '%place2%'...

Build the SQL with a for or while, just one of several feasible options.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文