ColdFusion and SoundEX
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
