7
7
<primary>test_parser</primary>
8
8
</indexterm>
9
9
10
+ <!--
11
+ <para>
12
+ <filename>test_parser</> is an example of a custom parser for full-text
13
+ search. It doesn't do anything especially useful, but can serve as
14
+ a starting point for developing your own parser.
15
+ </para>
16
+ -->
17
+
18
+ <para>
19
+ <filename>dblink</>是一个在数据库会话中支持连接其他<productname>PostgreSQL</>
20
+ 数据库的模块。
21
+ </para>
22
+
23
+
10
24
<para>
11
25
<filename>test_parser</> 是一个自定义的全文搜索解析器的例子。它不做特别有用的工作,但是可以作为开发一个自己的解析器的起点。
12
26
</para>
27
+
28
+ <!--
29
+ <para>
30
+ <filename>test_parser</> recognizes words separated by white space,
31
+ and returns just two token types:
32
+
33
+ <programlisting>
34
+ mydb=# SELECT * FROM ts_token_type('testparser');
35
+ tokid | alias | description
36
+ -------+-------+---------------
37
+ 3 | word | Word
38
+ 12 | blank | Space symbols
39
+ (2 rows)
40
+ </programlisting>
41
+
42
+ These token numbers have been chosen to be compatible with the default
43
+ parser's numbering. This allows us to use its <function>headline()</>
44
+ function, thus keeping the example simple.
45
+ </para>
46
+ -->
13
47
14
48
<para>
15
49
<filename>test_parser</> 识别以空格分隔的单词,并且返回两种令牌类型:
@@ -23,17 +57,49 @@ mydb=# SELECT * FROM ts_token_type('testparser');
23
57
(2 rows)
24
58
</programlisting>
25
59
26
- 这些令牌数字被选择来兼容默认的解析器编号。这允许我们可以使用 <function>headline()</>函数,从而保持例子的简单。
60
+ 这些令牌数字被选择来兼容默认的解析器编号。这让我们可以使用 <function>headline()</>函数,从而保持例子的简单。
27
61
</para>
28
62
63
+ <!--
64
+ <title>Usage</title>
65
+ -->
66
+
29
67
<sect2>
30
68
<title>用法</title>
31
69
70
+ <!--
71
+ <para>
72
+ Installing the <literal>test_parser</> extension creates a text search
73
+ parser <literal>testparser</>. It has no user-configurable parameters.
74
+ </para>
75
+ -->
76
+
32
77
<para>
33
- 安装<literal>test_parser</>扩展,创建一个文本搜索的解析器testparser 。它没有用户可配置参数。
78
+ 安装<literal>test_parser</>扩展,创建一个文本搜索解析器testparser 。它没有用户可配置参数。
34
79
35
80
</para>
36
81
82
+ <!--
83
+ <para>
84
+ You can test the parser with, for example,
85
+
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
+
37
103
<para>
38
104
你可以像下面的例子这样测试该解析器,
39
105
@@ -53,6 +119,35 @@ mydb=# SELECT * FROM ts_parse('testparser', 'That''s my first own parser');
53
119
3 | parser
54
120
</programlisting>
55
121
</para>
122
+
123
+ <!--
124
+ <para>
125
+ Real-world use requires setting up a text search configuration
126
+ 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
+ -->
56
151
57
152
<para>
58
153
实际使用需要配置一个文本搜索配置项来使用这个解析器。例如,
0 commit comments