简体   繁体   中英

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.

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. Eg: SELECT * FROM table WHERE city LIKE '%word%'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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