Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write sql query to get data which the best matches with data in database

Tags:

sql

database

I work on AI chat bot. I need sql query to select a single row from database where user input and text in database best matches. (also match percentage > %80)

For Example: "Hello" and "Hello!" , "Hi how are you" and "how are you?", "What is your name?" and "Wat is your name?"

My purpose is to get answer in case of clerical errors. Thanks in advance and sorry for my english

Bot LINK: http://developersland.net/chatbot/jessica.html

like image 662
Farid Movsumov Avatar asked Dec 31 '25 05:12

Farid Movsumov


1 Answers

Search a levenstein distance algoritm implementation on google (like this) and then

select text 
from mytable 
where levenshtein_ratio(text, 'text_to_compare') > 80 
limit 1 
like image 184
Florin stands with Ukraine Avatar answered Jan 07 '26 13:01

Florin stands with Ukraine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!