Skip to content

README updates #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ppazos opened this issue Dec 20, 2020 · 4 comments
Open

README updates #18

ppazos opened this issue Dec 20, 2020 · 4 comments

Comments

@ppazos
Copy link

ppazos commented Dec 20, 2020

Requires: sudo apt install libmysqlclient-dev
Before build.

After installing got:

$ gcc -o levenshtein.so -shared levenshtein.c mysql_config --include
/usr/bin/ld: /tmp/ccBcelTa.o: relocation R_X86_64_PC32 against symbol `levenshtein' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

Tried: $ gcc -o levenshtein.so -shared -fPIC levenshtein.c mysql_config --include

Worked OK, I can see the new .so file

@ppazos
Copy link
Author

ppazos commented Dec 20, 2020

mysql> CREATE FUNCTION levenshtein RETURNS INT SONAME 'levenshtein.so';
ERROR 1126 (HY000): Can't open shared library 'levenshtein.so' (errno: 2 /usr/lib/mysql/plugin/levenshtein.so: cannot open shared object file: No such file or directory)

After build, there is the need to copy the .so file to the location mentioned on the error above.

$ sudo cp levenshtein.so /usr/lib/mysql/plugin/

mysql> CREATE FUNCTION levenshtein RETURNS INT SONAME 'levenshtein.so';
Query OK, 0 rows affected (0.00 sec)

@ppazos
Copy link
Author

ppazos commented Dec 20, 2020

Just to confirm:

mysql>  select * from mysql.func;
+---------------------+-----+----------------+----------+
| name                | ret | dl             | type     |
+---------------------+-----+----------------+----------+
| levenshtein         |   2 | levenshtein.so | function |
| levenshtein_k       |   2 | levenshtein.so | function |
| levenshtein_k_ratio |   2 | levenshtein.so | function |
| levenshtein_ratio   |   2 | levenshtein.so | function |
+---------------------+-----+----------------+----------+

Testing: there is an error: levenshtein_ratio returns the same as levenshtein instead of 0..1


mysql> select levenshtein_ratio('MARIO','mario');
+------------------------------------+
| levenshtein_ratio('MARIO','mario') |
+------------------------------------+
|                                  5 |
+------------------------------------+
1 row in set (0.00 sec)

mysql> select levenshtein_ratio('Mario','mario');
+------------------------------------+
| levenshtein_ratio('Mario','mario') |
+------------------------------------+
|                                  1 |
+------------------------------------+
1 row in set (0.00 sec)

mysql> select levenshtein('Mario','mario');
+------------------------------+
| levenshtein('Mario','mario') |
+------------------------------+
|                            1 |
+------------------------------+
1 row in set (0.00 sec)

mysql> select levenshtein('MARIO','mario');
+------------------------------+
| levenshtein('MARIO','mario') |
+------------------------------+
|                            5 |
+------------------------------+
1 row in set (0.00 sec)

@ppazos
Copy link
Author

ppazos commented Dec 20, 2020

In fact, all functions return the same as levenshtein, here tested lev_k_ratio:

mysql> select levenshtein_k_ratio('mario','Mario',1);
+----------------------------------------+
| levenshtein_k_ratio('mario','Mario',1) |
+----------------------------------------+
|                                      1 |
+----------------------------------------+
1 row in set (0.00 sec)

mysql> select levenshtein_k_ratio('mario','mArio',1);
+----------------------------------------+
| levenshtein_k_ratio('mario','mArio',1) |
+----------------------------------------+
|                                      1 |
+----------------------------------------+
1 row in set (0.00 sec)

mysql> select levenshtein('mario','mArio');
+------------------------------+
| levenshtein('mario','mArio') |
+------------------------------+
|                            1 |
+------------------------------+
1 row in set (0.00 sec)

@ppazos
Copy link
Author

ppazos commented Dec 20, 2020

The only way to make the ratio work is by using levenshtein() /* the only function that works from mysql */ and calculating the ratio:

mysql> select (1- levenshtein('mario','Mario') / GREATEST(LENGTH('mario'), LENGTH('Mario')));
+--------------------------------------------------------------------------------+
| (1- levenshtein('mario','Mario') / GREATEST(LENGTH('mario'), LENGTH('Mario'))) |
+--------------------------------------------------------------------------------+
|                                                                         0.8000 |
+--------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant