TC_SoundEx Routine

Unit
IB_Utils

Declaration
Function TC_SoundEx(SourceStr: string ): longint;

Description
SoundEx algorithm - supplied by Telesis Computing. ~TC~

The TC_SoundEx and TC_SoundExMax are extensions to the SoundEx concept - creating values which can be used to allow string values that "sound" alike to be sorted together. This is a Pascal implementation of the C++ code which I use in my own C++Builder application and Interbase UDF. (Obviously the code used by your application MUST match the code used by the server!)

I have supplied this code for convenience. You can use it or not as you like.

For those who would rather a more standard SoundEx implementation, you may like to look at the FreeUDF library written by Gregory Deatz which provides (in Pascal) code which can be used in both a UDF and your application.

Besides the FreeUDF library there is also some information on the Interbase web-site which goes into how and why the SoundEx algorithm works. I won't try and repeat that here.

My extensions to the SoundEx algorithm have two main purposes...

1. By implementing a full 32bit value I can use 8 or 9 significant characters from the source string making the result much more specific for longer strings. (Less duplication in the indexes.)

2. By implementing the SoundEx and SoundExMax algorithms correctly it is possible to perform a select on a string that "sounds" like it "starts" with a particular text. Essentially this is a partial key style match but using the "fuzzy" matching of SoundEx.

These implementations return integer (32bit) values. If you are going to use these in conjunction with the TIB_Connection.OnSoundExParse and TIB_Connection.OnSoundExMaxParse then you will need to include the following code in the resulting event handler...

ResultStr := IntToStr( TC_SoundEx( SourceStr ) );

Implementation made at the bottom of this module.