On Mon, 14 Nov 2005, Rhino wrote:

If you are asking whether MySQL already has a function that will calculate a
levenshtein-distance, I'm pretty sure that the answer is no. You can check
the MySQL manual yourself to be sure. The (English language manuals are at
http://dev.mysql.com/doc/ and other translations of the manuals can also be
accessed from that same page. You'll need to choose the appropriate manual
based on your version of MySQL; then look in the Functions and Operators
chapter.)

If you are asking whether MySQL supports user-defined functions (UDFs),
which allow you to add your own functions to MySQL, the answer is yes,
provided you are using Version 5 of MySQL. That means that if you can write

no v3 and v4 can too

the logic needed to calculate a levenshtein-distance in C or C++, you can
create your own UDF and add it to MySQL, then invoke it via the function
name in your SQL.

Possible problem: I see from your example that you want to put the function
in your ORDER BY clause; I'm not sure if you can do *that* in MySQL; I think

yes they can, but not efficient
... order by rand() ...

functions have to be invoked from the SELECT clause or HAVING clause or
maybe a few other places; I've never seen a function invoked in an ORDER BY
in either MySQL or DB2, which I know considerably better than MySQL. You may
want to try writing a trivial function and then seeing if you can invoke it
from an ORDER BY before you spend much time on the levenshtein-distance
function.... Of course, you could always rewrite your query so that the
function is invoked from the SELECT, like this:

select word1,word2, dist(word1, word2) from myTable order by 3

where the '3' in the ORDER BY clause indicates the third column of the
SELECT clause. That should be just as good as your original query.

Rhino


----- Original Message -----
From: "Horst Jäger" <[EMAIL PROTECTED]>
To: <mysql@lists.mysql.com>
Sent: Monday, November 14, 2005 11:02 AM
Subject: Let mysql calculate levenshtein-distance



Hi,

I have a nice little code snippet in pseudocode, which calculates the
levenshtein-distance between 2 words.

Is it possible to implement that code in mysql like in

"select word1,word2 from myTable order by dist(word1,word2 )"

where dist is the function mentionend above which takes 2 strings and
returns an int?

Weird question??? :)

Thanks

Horst


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.0/167 - Release Date: 11/11/2005







--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                               -
- Jason Pyeron                      PD Inc. http://www.pdinc.us -
- Partner & Sr. Manager             7 West 24th Street #100     -
- +1 (443) 269-1555                 Baltimore, Maryland 21218   -
-                                                               -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, purge the message from your system and notify the sender immediately. Any other use of the email by you is prohibited.
-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to