[EMAIL PROTECTED] writes:

> The code in /contrib/soundex doesn't work. It does compile though. I
> create the function in the database, but it always returns nothing
> (blank)!

Hmm, while I can confirm that the soundex algorithm is implemented
incorrectly I never get blanks only.  Check that you have defined the
function like this:

    CREATE FUNCTION soundex(text) RETURNS text AS
      '/some/where/soundex.so', 'text_soundex' LANGUAGE 'C';

(ignore the stuff in soundex.sql, it's broken).

To get a correct implementation of soundex, apply the attached patch.  
You need to restart the server to get it to load the new object file.

Also note that there is a disagreement among experts over one particular
part of the algorithm.  Check it out with your favourite search engine.


-- 
Peter Eisentraut      [EMAIL PROTECTED]       http://yi.org/peter-e/
*** soundex.c.orig      Fri Sep 29 16:25:59 2000
--- soundex.c   Fri Sep 29 16:29:48 2000
***************
*** 21,27 ****
        int                     count = 0;
        text       *new_t;
  
!       char            outstr[6 + 1];  /* max length of soundex is 6 */
        char       *instr;
  
        /* make a null-terminated string */
--- 21,27 ----
        int                     count = 0;
        text       *new_t;
  
!       char            outstr[4 + 1];  /* max length of soundex is 4 */
        char       *instr;
  
        /* make a null-terminated string */
***************
*** 70,76 ****
  
        *outstr++ = (char) toupper(*instr++);
  
!       while (*instr && count < 5)
        {
                if (isalpha(*instr) && *instr != *(instr - 1))
                {
--- 70,76 ----
  
        *outstr++ = (char) toupper(*instr++);
  
!       while (*instr && count < 3)
        {
                if (isalpha(*instr) && *instr != *(instr - 1))
                {
***************
*** 82,87 ****
--- 82,94 ----
                        }
                }
                ++instr;
+       }
+ 
+       while (count < 3)
+       {
+               *outstr = '0';
+               ++outstr;
+               ++count;
        }
  
        *outstr = '\0';

Reply via email to