Skip to main content
Participant
March 30, 2010
Question

ColdFusion and SoundEX

  • March 30, 2010
  • 2 replies
  • 817 views

Hey,

I'm trying to find a more efficient way to use SoundEX to find duplicated names in a database.  Here is my code so far

<cfset o = createObject("component", "cfc.soundex").init() /> <cfset s = structNew() /> <cfquery name="FindUsers" datasource="#request.dsn#" maxrows="100">      SELECT ID, FirstName, LastName FROM dbo.Users_Info      WHERE ((LEN(FirstName) > 0) AND (FirstName NOT LIKE '%[-+=!$@_:;,.^0-9]%')) AND ((LEN(LastName) > 0) AND (LastName NOT LIKE '%[-+=!$@_:;,.^0-9]%'))      ORDER BY LastName ASC </cfquery> <cfloop query="FindUsers">      <cfset o.addToDictionary(#rereplace(FindUsers.FirstName, '@"[$1(\P{M}\p{M})]', '', 'all')# & " " & #rereplace(FindUsers.LastName, '@"[$1(\P{M}\p{M})]', '', 'all')#) /> </cfloop> <cfloop query="FindUsers">      <cftry>           <cfset s.word = #rereplace(FindUsers.FirstName, '@"[$1(\P{M}\p{M})]', '', 'all')# & " " & #rereplace(FindUsers.LastName, '@"[$1(\P{M}\p{M})]', '', 'all')# />           <cfset s.threshold = 1 />           <cfset s.soundex = o.getSoundexValue(s.word) />           <cfset s.result = o.returnSoundexMatches(s.word, s.threshold) />                     <cfoutput>                     <p style="text-align:left;border-width:2px;border-style:solid;border-color:003366;padding:2px;">                User ID: <strong>#FindUsers.ID#</strong> <br />                SoundEX Value: <strong>#s.soundex#</strong> <br />                The Users First and Last Name: <strong>#s.word#</strong><br /><br />                Possible Duplicates: <br />                <cfloop from="1" to="#arrayLen(s.result)#" index="index">                     <strong>#s.result[index].candidate#</strong><br />                </cfloop>           </p>                     </cfoutput>                <cfcatch type="Any">                #cfcatch.Detail#           </cfcatch>      </cftry> </cfloop>

Any feedback would be great!!!

Message was edited by: tready7179 -- Code didnt show

    This topic has been closed for replies.

    2 replies

    Owainnorth
    Inspiring
    March 31, 2010

    Whilst not pretending to know anything about SoundEx at all, don't Oracle and SQLServer have Soundex functionality built-in as standard?

    If it's usable for your needs it'll save you a heck of a lot of time.

    O.

    AdamPresley
    Participating Frequently
    March 31, 2010

    Heh, I recognize that code. Looks like my implementation of http://www.creativyst.com soundex algorithm, http://blog.adampresley.com/2008/coldfusion-soundex-algorithm-component/. Not sure I understand why you wanna use Soundex for finding "duplicate" names, when the intent of Soundex is to find similar strings within a threshold.