14
14
a starting point for developing your own parser.
15
15
</para>
16
16
-->
17
-
18
- <para>
19
- <filename>dblink</>是一个在数据库会话中支持连接其他<productname>PostgreSQL</>
20
- 数据库的模块。
21
- </para>
22
-
23
-
24
17
<para>
25
18
<filename>test_parser</> 是一个自定义的全文搜索解析器的例子。它不做特别有用的工作,但是可以作为开发一个自己的解析器的起点。
26
19
</para>
27
20
28
- <!--
29
21
<para>
22
+ <!--
30
23
<filename>test_parser</> recognizes words separated by white space,
31
24
and returns just two token types:
25
+ -->
26
+ <filename>test_parser</> 识别以空格分隔的单词,并且返回两种标记类型:
32
27
33
28
<programlisting>
34
29
mydb=# SELECT * FROM ts_token_type('testparser');
@@ -39,25 +34,13 @@ mydb=# SELECT * FROM ts_token_type('testparser');
39
34
(2 rows)
40
35
</programlisting>
41
36
37
+ <!--
42
38
These token numbers have been chosen to be compatible with the default
43
39
parser's numbering. This allows us to use its <function>headline()</>
44
40
function, thus keeping the example simple.
45
41
</para>
46
42
-->
47
-
48
- <para>
49
- <filename>test_parser</> 识别以空格分隔的单词,并且返回两种令牌类型:
50
-
51
- <programlisting>
52
- mydb=# SELECT * FROM ts_token_type('testparser');
53
- tokid | alias | description
54
- -------+-------+---------------
55
- 3 | word | Word
56
- 12 | blank | Space symbols
57
- (2 rows)
58
- </programlisting>
59
-
60
- 这些令牌数字被选择来兼容默认的解析器编号。这让我们可以使用<function>headline()</>函数,从而保持例子的简单。
43
+ 这些标记数字被选择来兼容默认的解析器编号。这让我们可以使用<function>headline()</>函数,从而保持例子的简单。
61
44
</para>
62
45
63
46
<!--
@@ -79,30 +62,12 @@ mydb=# SELECT * FROM ts_token_type('testparser');
79
62
80
63
</para>
81
64
82
- <!--
83
- <para>
84
- You can test the parser with, for example,
85
65
86
- <programlisting>
87
- mydb=# SELECT * FROM ts_parse('testparser', 'That''s my first own parser');
88
- tokid | token
89
- -------+--------
90
- 3 | That's
91
- 12 |
92
- 3 | my
93
- 12 |
94
- 3 | first
95
- 12 |
96
- 3 | own
97
- 12 |
98
- 3 | parser
99
- </programlisting>
100
- </para>
101
- -->
102
-
103
66
<para>
67
+ <!--
68
+ You can test the parser with, for example,
69
+ -->
104
70
你可以像下面的例子这样测试该解析器,
105
-
106
71
107
72
<programlisting>
108
73
mydb=# SELECT * FROM ts_parse('testparser', 'That''s my first own parser');
@@ -119,39 +84,15 @@ mydb=# SELECT * FROM ts_parse('testparser', 'That''s my first own parser');
119
84
3 | parser
120
85
</programlisting>
121
86
</para>
87
+
122
88
123
- <!--
89
+
124
90
<para>
91
+ <!--
125
92
Real-world use requires setting up a text search configuration
126
93
that uses the parser. For example,
127
-
128
- <programlisting>
129
- mydb=# CREATE TEXT SEARCH CONFIGURATION testcfg ( PARSER = testparser );
130
- CREATE TEXT SEARCH CONFIGURATION
131
-
132
- mydb=# ALTER TEXT SEARCH CONFIGURATION testcfg
133
- mydb-# ADD MAPPING FOR word WITH english_stem;
134
- ALTER TEXT SEARCH CONFIGURATION
135
-
136
- mydb=# SELECT to_tsvector('testcfg', 'That''s my first own parser');
137
- to_tsvector
138
- -------------------------------
139
- 'that':1 'first':3 'parser':5
140
- (1 row)
141
-
142
- mydb=# SELECT ts_headline('testcfg', 'Supernovae stars are the brightest phenomena in galaxies',
143
- mydb(# to_tsquery('testcfg', 'star'));
144
- ts_headline
145
- -----------------------------------------------------------------
146
- Supernovae <b>stars</b> are the brightest phenomena in galaxies
147
- (1 row)
148
- </programlisting>
149
- </para>
150
- -->
151
-
152
- <para>
94
+ -->
153
95
实际使用需要配置一个文本搜索配置项来使用这个解析器。例如,
154
-
155
96
156
97
<programlisting>
157
98
mydb=# CREATE TEXT SEARCH CONFIGURATION testcfg ( PARSER = testparser );
@@ -176,6 +117,7 @@ mydb(# to_tsquery('testcfg', 'star'));
176
117
</programlisting>
177
118
</para>
178
119
120
+
179
121
</sect2>
180
122
181
123
</sect1>
0 commit comments