简体   繁体   English

在数据库中查找匹配的单词和一个长字符串

[英]Find matching words in a database and a long string

I have a large database of cities and towns (around 300 000) and I am trying -using python- to check if a given string contains one of these cities. 我有一个庞大的城市和城镇数据库(大约30万个),我正在尝试-使用python-检查给定的字符串是否包含这些城市之一。

What is the optimal way to achieve this? 实现此目标的最佳方法是什么?

Though not the most optimal way to do it, but one way could be to split your long string into list of words. 尽管这不是最理想的方法,但是一种方法可能是将长字符串分成单词列表。 Then for each word query the database using LIKE regex. 然后,对于每个单词,使用LIKE正则表达式查询数据库。 Eg: SELECT * FROM table WHERE city LIKE '%word%' 例如: SELECT * FROM table WHERE city LIKE '%word%'

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

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