-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtextsearch_ja-9.4.sql
More file actions
127 lines (104 loc) · 2.95 KB
/
textsearch_ja-9.4.sql
File metadata and controls
127 lines (104 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
SET search_path = public;
--
-- Japanese text parser
--
CREATE FUNCTION ts_ja_start(internal, int4)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'c' STRICT;
CREATE FUNCTION ts_ja_gettoken(internal, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'c' STRICT;
CREATE FUNCTION ts_ja_end(internal)
RETURNS void
AS 'MODULE_PATHNAME'
LANGUAGE 'c' STRICT;
CREATE TEXT SEARCH PARSER pg_catalog.japanese (
START = ts_ja_start,
GETTOKEN = ts_ja_gettoken,
END = ts_ja_end,
HEADLINE = pg_catalog.prsd_headline,
LEXTYPES = pg_catalog.prsd_lextype
);
COMMENT ON TEXT SEARCH PARSER pg_catalog.japanese IS
'japanese word parser';
--
-- Japanese text lexizer
--
CREATE FUNCTION ts_ja_lexize(internal, internal, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'c' STRICT;
CREATE TEXT SEARCH TEMPLATE pg_catalog.mecab (
LEXIZE = ts_ja_lexize
);
CREATE TEXT SEARCH DICTIONARY pg_catalog.japanese_stem (
TEMPLATE = pg_catalog.mecab
);
--
-- Japanese text configuration
--
CREATE TEXT SEARCH CONFIGURATION pg_catalog.japanese (PARSER = japanese);
COMMENT ON TEXT SEARCH CONFIGURATION pg_catalog.japanese IS
'configuration for japanese language';
ALTER TEXT SEARCH CONFIGURATION pg_catalog.japanese ADD MAPPING
FOR email, url, url_path, host, file, version,
sfloat, float, int, uint,
numword, hword_numpart, numhword
WITH simple;
-- Default configuration is Japanese-English.
-- Replace english_stem if you use other language.
ALTER TEXT SEARCH CONFIGURATION pg_catalog.japanese ADD MAPPING
FOR asciiword, hword_asciipart, asciihword
WITH english_stem;
ALTER TEXT SEARCH CONFIGURATION pg_catalog.japanese ADD MAPPING
FOR word, hword_part, hword
WITH japanese_stem;
--
-- Utility functions
--
CREATE FUNCTION ja_analyze(
text,
OUT word text,
OUT type text,
OUT subtype1 text,
OUT subtype2 text,
OUT subtype3 text,
OUT conjtype text,
OUT conjugation text,
OUT basic text,
OUT ruby text,
OUT pronounce text)
RETURNS SETOF record
AS 'MODULE_PATHNAME'
LANGUAGE 'c' IMMUTABLE STRICT;
CREATE FUNCTION ja_normalize(text)
RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE 'c' IMMUTABLE STRICT;
CREATE FUNCTION ja_wakachi(text)
RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE 'c' IMMUTABLE STRICT;
CREATE FUNCTION web_query(text) RETURNS text AS
$$
SELECT regexp_replace(regexp_replace(regexp_replace($1,
E'(^|\\s+)-', E'\\1!', 'g'),
E'\\s+OR\\s+', '|', 'g'),
E'\\s+', '&', 'g');
$$
LANGUAGE sql IMMUTABLE STRICT;
CREATE FUNCTION furigana(text)
RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE 'c' IMMUTABLE STRICT;
CREATE FUNCTION hiragana(text)
RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE 'c' IMMUTABLE STRICT;
CREATE FUNCTION katakana(text)
RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE 'c' IMMUTABLE STRICT;
--