node.js - MySQL Similar values in VARCHAR column -


i have database table storing restaurant names , city located in. example:

name | city

eleven madison park | nyc

gramercy tavern | nyc

lotus of siam | tok

the modern | la

abc kitchen | la

now when there incoming entry before insert, if there no similar restaurant name in same city, want go ahead , perform insert.

but if entry like, { name: "eleven madison", city: "nyc" }, want find similar entries in "name" column same city, in example "eleven madison park" in "nyc", want insert , store new row in 'conflicts' table - ids of these restaurants (last insert id , similar row id)

i used levenshtein distance algorithm, following sql query:

select id, levenshtein_ratio(name, 'eleven madison') levsh restaurants city_name = 'nyc' order levsh asc limit 0, 1 

then set threshold of 8, , if levsh less 8, mark conflict i.e. insert new record in 'conflicts' table. query working fine until table grew 1000 records. query takes 2 seconds finish.

i understand because calculating levenshtein_ratio restaurants in city - , need apply ratio function on similar names ex. ones containing 'eleven' , 'madison',.. or better if can like

where city_name = 'nyc' , soundex(any word in `name`) = soundex(any word in 'eleven madison') 

please suggestions on how improve , optimize query, , if possible better approach doing.

thanks


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -