Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
18d99bc2
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
18d99bc2
编写于
10月 04, 2000
作者:
P
Peter Eisentraut
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update soundex to new fmgr interface and fix algorithm
上级
baa3a09b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
98 addition
and
57 deletion
+98
-57
contrib/soundex/Makefile
contrib/soundex/Makefile
+4
-4
contrib/soundex/README.soundex
contrib/soundex/README.soundex
+14
-1
contrib/soundex/soundex.c
contrib/soundex/soundex.c
+77
-50
contrib/soundex/soundex.sql.in
contrib/soundex/soundex.sql.in
+3
-2
未找到文件。
contrib/soundex/Makefile
浏览文件 @
18d99bc2
#
# $Header: /cvsroot/pgsql/contrib/soundex/Attic/Makefile,v 1.
7 2000/07/09 13:13:33
petere Exp $
# $Header: /cvsroot/pgsql/contrib/soundex/Attic/Makefile,v 1.
8 2000/10/04 19:25:34
petere Exp $
#
subdir
=
contrib/soundex
top_builddir
=
../..
include
../..
/src/Makefile.global
include
$(top_builddir)
/src/Makefile.global
NAME
:=
soundex
SONAME
:=
$(NAME)$(DLSUFFIX)
...
...
@@ -14,7 +14,7 @@ CFLAGS += -I. $(CFLAGS_SL)
all
:
$(SONAME) $(NAME).sql
$(NAME).sql
:
$(NAME).sql.in
sed
-e
's:MODULE_PATHNAME:
$(datadir)
/contrib/
$(SONAME)
:g'
<
$<
>
$@
sed
's,@MODULE_FILENAME@,
$(libdir)
/contrib/
$(SONAME)
,g'
$<
>
$@
install
:
all installdirs
$(INSTALL_SHLIB)
$(SONAME)
$(libdir)
/contrib
...
...
@@ -28,7 +28,7 @@ uninstall:
rm
-f
$(libdir)
/contrib/
$(SONAME)
$(datadir)
/contrib/
$(NAME)
.sql
$(docdir)
/contrib/README.
$(NAME)
clean distclean maintainer-clean
:
rm
-f
$(SONAME)
$(NAME)
.sql
rm
-f
$(SONAME)
$(NAME)
.
o
$(NAME)
.
sql
depend dep
:
$(CC)
-MM
-MG
$(CFLAGS)
*
.c
>
depend
...
...
contrib/soundex/README.soundex
浏览文件 @
18d99bc2
This directory contains a module that implements the "Soundex" code as
a PostgreSQL user-defined function. The Soundex system is a method of
matching similar sounding names (or any words) to the same code. It
was initially used by the United States Census in 1880, 1900, and
1910, but it has little use beyond English names (or the English
pronunciation of names), and it is not a linguistic tool.
To install it, first configure the main source tree, then run make;
make install in this directory. Finally, load the function definition
with psql:
psql -f PREFIX/share/contrib/soundex.sql
The following are some usage examples:
SELECT text_soundex('hello world!');
...
...
@@ -50,4 +64,3 @@ WHERE text_sx_eq(nm,'john')\g
SELECT *
from s
where s.nm #= 'john';
contrib/soundex/soundex.c
浏览文件 @
18d99bc2
/*
***************************************************************************
*/
/* soundex.c */
/*****************************************************************************/
/*
$Header: /cvsroot/pgsql/contrib/soundex/Attic/soundex.c,v 1.7 2000/10/04 19:25:34 petere Exp $
*/
#include "postgres.h"
#include "fmgr.h"
#include "utils/builtins.h"
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include "postgres.h"
/* for char16, etc. */
#include "utils/palloc.h"
/* for palloc */
Datum
text_soundex
(
PG_FUNCTION_ARGS
);
/* prototypes for soundex functions */
text
*
text_soundex
(
text
*
t
);
char
*
soundex
(
char
*
instr
,
char
*
outstr
);
static
void
soundex
(
const
char
*
instr
,
char
*
outstr
);
text
*
text_soundex
(
text
*
t
)
{
text
*
new_t
;
#define SOUNDEX_LEN 4
char
outstr
[
6
+
1
];
/* max length of soundex is 6 */
char
*
instr
;
/* make a null-terminated string */
instr
=
palloc
(
VARSIZE
(
t
)
+
1
);
memcpy
(
instr
,
VARDATA
(
t
),
VARSIZE
(
t
)
-
VARHDRSZ
);
instr
[
VARSIZE
(
t
)
-
VARHDRSZ
]
=
(
char
)
0
;
#define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
#define _textout(str) DatumGetPointer(DirectFunctionCall1(textout, PointerGetDatum(str)))
/* load soundex into outstr */
soundex
(
instr
,
outstr
);
/* Now the outstr contains the soundex of instr */
/* copy outstr to new_t */
new_t
=
(
text
*
)
palloc
(
strlen
(
outstr
)
+
VARHDRSZ
);
memset
(
new_t
,
0
,
strlen
(
outstr
)
+
1
);
VARSIZE
(
new_t
)
=
strlen
(
outstr
)
+
VARHDRSZ
;
memcpy
((
void
*
)
VARDATA
(
new_t
),
(
void
*
)
outstr
,
strlen
(
outstr
));
#ifndef SOUNDEX_TEST
/*
* SQL function: text_soundex(text) returns text
*/
Datum
text_soundex
(
PG_FUNCTION_ARGS
)
{
char
outstr
[
SOUNDEX_LEN
+
1
];
char
*
arg
;
arg
=
_textout
(
PG_GETARG_TEXT_P
(
0
));
/* free instr */
pfree
(
instr
);
soundex
(
arg
,
outstr
);
return
(
new_t
);
PG_RETURN_TEXT_P
(
_textin
(
outstr
)
);
}
#endif
/* not SOUNDEX_TEST */
/* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
static
const
char
*
soundex_table
=
"01230120022455012623010202"
;
#define soundex_code(letter) soundex_table[toupper(letter) - 'A']
char
*
soundex
(
char
*
instr
,
char
*
outstr
)
static
void
soundex
(
c
onst
c
har
*
instr
,
char
*
outstr
)
{
/* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
char
*
table
=
"01230120022455012623010202"
;
int
count
=
0
;
int
count
;
AssertArg
(
instr
);
AssertArg
(
outstr
);
outstr
[
SOUNDEX_LEN
]
=
'\0'
;
/* Skip leading non-alphabetic characters */
while
(
!
isalpha
(
instr
[
0
])
&&
instr
[
0
])
++
instr
;
/* No string left */
if
(
!
instr
[
0
])
{
/* Hey! Where'd the string go? */
outstr
[
0
]
=
(
char
)
0
;
return
outstr
;
}
if
(
toupper
(
instr
[
0
])
==
'P'
&&
toupper
(
instr
[
1
])
==
'H'
)
{
instr
[
0
]
=
'F'
;
instr
[
1
]
=
'A'
;
outstr
[
0
]
=
(
char
)
0
;
return
;
}
/* Take the first letter as is */
*
outstr
++
=
(
char
)
toupper
(
*
instr
++
);
while
(
*
instr
&&
count
<
5
)
count
=
1
;
while
(
*
instr
&&
count
<
SOUNDEX_LEN
)
{
if
(
isalpha
(
*
instr
)
&&
*
instr
!=
*
(
instr
-
1
))
if
(
isalpha
(
*
instr
)
&&
soundex_code
(
*
instr
)
!=
soundex_code
(
*
(
instr
-
1
)
))
{
*
outstr
=
table
[
toupper
(
instr
[
0
])
-
'A'
]
;
*
outstr
=
soundex_code
(
instr
[
0
])
;
if
(
*
outstr
!=
'0'
)
{
++
outstr
;
...
...
@@ -83,6 +83,33 @@ soundex(char *instr, char *outstr)
++
instr
;
}
*
outstr
=
'\0'
;
return
(
outstr
);
/* Fill with 0's */
while
(
count
<
SOUNDEX_LEN
)
{
*
outstr
=
'0'
;
++
outstr
;
++
count
;
}
}
#ifdef SOUNDEX_TEST
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"usage: %s string
\n
"
,
argv
[
0
]);
return
1
;
}
else
{
char
output
[
SOUNDEX_LEN
+
1
];
soundex
(
argv
[
1
],
output
);
printf
(
"soundex(%s) = %s
\n
"
,
argv
[
1
],
output
);
return
0
;
}
}
#endif
/* SOUNDEX_TEST */
contrib/soundex/soundex.sql.in
浏览文件 @
18d99bc2
CREATE FUNCTION text_soundex(text) RETURNS text
AS 'MODULE_PATHNAME' LANGUAGE 'c
';
AS '@MODULE_FILENAME@', 'text_soundex' LANGUAGE 'newC
';
CREATE FUNCTION soundex(text) RETURNS text
AS '@MODULE_FILENAME@', 'text_soundex' LANGUAGE 'newC';
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录