1test_parser is an example of a custom parser for full-text
2search.  It doesn't do anything especially useful, but can serve as
3a starting point for developing your own parser.
4
5test_parser recognizes words separated by white space,
6and returns just two token types:
7
8mydb=# SELECT * FROM ts_token_type('testparser');
9 tokid | alias |  description
10-------+-------+---------------
11     3 | word  | Word
12    12 | blank | Space symbols
13(2 rows)
14
15These token numbers have been chosen to be compatible with the default
16parser's numbering.  This allows us to use its headline()
17function, thus keeping the example simple.
18
19Usage
20=====
21
22Installing the test_parser extension creates a text search
23parser testparser.  It has no user-configurable parameters.
24
25You can test the parser with, for example,
26
27mydb=# SELECT * FROM ts_parse('testparser', 'That''s my first own parser');
28 tokid | token
29-------+--------
30     3 | That's
31    12 |
32     3 | my
33    12 |
34     3 | first
35    12 |
36     3 | own
37    12 |
38     3 | parser
39
40Real-world use requires setting up a text search configuration
41that uses the parser.  For example,
42
43mydb=# CREATE TEXT SEARCH CONFIGURATION testcfg ( PARSER = testparser );
44CREATE TEXT SEARCH CONFIGURATION
45
46mydb=# ALTER TEXT SEARCH CONFIGURATION testcfg
47mydb-#   ADD MAPPING FOR word WITH english_stem;
48ALTER TEXT SEARCH CONFIGURATION
49
50mydb=#  SELECT to_tsvector('testcfg', 'That''s my first own parser');
51          to_tsvector
52-------------------------------
53 'that':1 'first':3 'parser':5
54(1 row)
55
56mydb=# SELECT ts_headline('testcfg', 'Supernovae stars are the brightest phenomena in galaxies',
57mydb(#                    to_tsquery('testcfg', 'star'));
58                           ts_headline
59-----------------------------------------------------------------
60 Supernovae <b>stars</b> are the brightest phenomena in galaxies
61(1 row)
62