|
| 1 | +<sect1 id="pg-tsparser"> |
| 2 | + <title>pg_tsparser</title> |
| 3 | + <para> |
| 4 | + The <filename>pg_tsparser</filename> is a Postgres Pro extension that |
| 5 | + modifies the default text search parser. In addition to the default |
| 6 | + search results, this extension also returns a single word in the |
| 7 | + following cases: |
| 8 | + </para> |
| 9 | + <itemizedlist spacing="compact"> |
| 10 | + <listitem> |
| 11 | + <para> |
| 12 | + words that include underscores |
| 13 | + </para> |
| 14 | + </listitem> |
| 15 | + <listitem> |
| 16 | + <para> |
| 17 | + words that include numbers and letters separated by the hyphen |
| 18 | + character |
| 19 | + </para> |
| 20 | + </listitem> |
| 21 | + </itemizedlist> |
| 22 | + <sect2 id="pg-tsparser-install"> |
| 23 | + <title>Installation and Setup</title> |
| 24 | + <para> |
| 25 | + The <filename>pg_tsparser</filename> extension is included into the |
| 26 | + Postgres Pro. To enable <filename>pg_tsparser</filename>, |
| 27 | + create the <filename>pg_tsparser</filename> extension for each |
| 28 | + database you are planning to use: |
| 29 | + </para> |
| 30 | + <programlisting> |
| 31 | +CREATE EXTENSION pg_tsparser; |
| 32 | +</programlisting> |
| 33 | + <para> |
| 34 | + Once <filename>pg_tsparser</filename> is enabled, you can create |
| 35 | + your own text search configuration. For example: |
| 36 | + </para> |
| 37 | + <programlisting> |
| 38 | +CREATE TEXT SEARCH CONFIGURATION english_ts ( |
| 39 | + PARSER = tsparser |
| 40 | +); |
| 41 | + |
| 42 | +COMMENT ON TEXT SEARCH CONFIGURATION english_ts IS 'text search configuration for english language'; |
| 43 | + |
| 44 | +ALTER TEXT SEARCH CONFIGURATION english_ts |
| 45 | + ADD MAPPING FOR email, file, float, host, hword_numpart, int, |
| 46 | + numhword, numword, sfloat, uint, url, url_path, version |
| 47 | + WITH simple; |
| 48 | + |
| 49 | +ALTER TEXT SEARCH CONFIGURATION english_ts |
| 50 | + ADD MAPPING FOR asciiword, asciihword, hword_asciipart, |
| 51 | + word, hword, hword_part |
| 52 | + WITH english_stem; |
| 53 | +</programlisting> |
| 54 | + </sect2> |
| 55 | + <sect2 id="pg-tsparser-examples"> |
| 56 | + <title>Examples</title> |
| 57 | + <para> |
| 58 | + The following examples illustrate the difference in search results |
| 59 | + returned by <filename>pg_tsparser</filename> and the default parser: |
| 60 | + </para> |
| 61 | + <programlisting> |
| 62 | +SELECT to_tsvector('english', 'pg_trgm') as def_parser, |
| 63 | + to_tsvector('english_ts', 'pg_trgm') as new_parser; |
| 64 | + def_parser | new_parser |
| 65 | +-----------------+----------------------------- |
| 66 | + 'pg':1 'trgm':2 | 'pg':2 'pg_trgm':1 'trgm':3 |
| 67 | +(1 row) |
| 68 | + |
| 69 | +SELECT to_tsvector('english', '123-abc') as def_parser, |
| 70 | + to_tsvector('english_ts', '123-abc') as new_parser; |
| 71 | + def_parser | new_parser |
| 72 | +-----------------+----------------------------- |
| 73 | + '123':1 'abc':2 | '123':2 '123-abc':1 'abc':3 |
| 74 | +(1 row) |
| 75 | + |
| 76 | +SELECT to_tsvector('english', 'rel-3.2-A') as def_parser, |
| 77 | + to_tsvector('english_ts', 'rel-3.2-A') as new_parser; |
| 78 | + def_parser | new_parser |
| 79 | +------------------+------------------------------- |
| 80 | + '-3.2':2 'rel':1 | '3.2':3 'rel':2 'rel-3.2-a':1 |
| 81 | +(1 row) |
| 82 | +</programlisting> |
| 83 | + </sect2> |
| 84 | + <sect2 id="pg-tsparser-authors"> |
| 85 | + <title>Authors</title> |
| 86 | + <para> |
| 87 | + Postgres Professional, Moscow, Russia |
| 88 | + </para> |
| 89 | + </sect2> |
| 90 | +</sect1> |
0 commit comments