Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL function for checking similarity percentage between two texts

I need MySQL code for checking similarity percentage between text submitted via form against a number of texts stored in MySQL database.

I am looking for MySQL stored procedure that will work the like PHP's similar_text() function. There is already MySQL Levenshtein distance procedure but it's not sufficient.

When the user submits the text the algorithm should return any entry in database with given percentage of similarity to the text submitted (it will compare only one column in database), e.g return all entries from database that have similarity > 40% with the text submitted by the user.

E.g table

TABLE - Articles
id, article_body, article_title

Code should return all rows that have similarity percentage > 40% (or other given value) with the text (article_body) the user have submitted.

like image 535
user990788 Avatar asked Oct 12 '11 05:10

user990788


1 Answers

I'd do it in the application.

Maybe result of SOUNDEX function will help you -

SELECT SOUNDEX('Hello'), SOUNDEX('Hello world'), SOUNDEX('hellboy');
+------------------+------------------------+--------------------+
| SOUNDEX('Hello') | SOUNDEX('Hello world') | SOUNDEX('hellboy') |
+------------------+------------------------+--------------------+
| H400             | H4643                  | H410               |
+------------------+------------------------+--------------------+
like image 130
Devart Avatar answered Oct 20 '22 18:10

Devart