3 <sect1 id=
"test-parser">
4 <title>test_parser
</title>
6 <indexterm zone=
"test-parser">
7 <primary>test_parser
</primary>
11 <filename>test_parser<
/> is an example of a custom parser for full-text
12 search. It doesn't do anything especially useful, but can serve as
13 a starting point for developing your own parser.
17 <filename>test_parser<
/> recognizes words separated by white space,
18 and returns just two token types:
21 mydb=# SELECT * FROM ts_token_type('testparser');
22 tokid | alias | description
23 -------+-------+---------------
25 12 | blank | Space symbols
29 These token numbers have been chosen to be compatible with the default
30 parser's numbering. This allows us to use its
<function>headline()<
/>
31 function, thus keeping the example simple.
38 Running the installation script creates a text search parser
39 <literal>testparser<
/>. It has no user-configurable parameters.
43 You can test the parser with, for example,
46 mydb=# SELECT * FROM ts_parse('testparser', 'That''s my first own parser');
62 Real-world use requires setting up a text search configuration
63 that uses the parser. For example,
66 mydb=# CREATE TEXT SEARCH CONFIGURATION testcfg ( PARSER = testparser );
67 CREATE TEXT SEARCH CONFIGURATION
69 mydb=# ALTER TEXT SEARCH CONFIGURATION testcfg
70 mydb-# ADD MAPPING FOR word WITH english_stem;
71 ALTER TEXT SEARCH CONFIGURATION
73 mydb=# SELECT to_tsvector('testcfg', 'That''s my first own parser');
75 -------------------------------
76 'that':
1 'first':
3 'parser':
5
79 mydb=# SELECT ts_headline('testcfg', 'Supernovae stars are the brightest phenomena in galaxies',
80 mydb(# to_tsquery('testcfg', 'star'));
82 -----------------------------------------------------------------
83 Supernovae
<b
>stars
</b
> are the brightest phenomena in galaxies