Postgresql full text match unexpected

Viewed 259

Looking at the following queries:

1. select to_tsvector('xyz-abc-testbed') @@ to_tsquery('abc')  # true
2. select to_tsvector('xyz/xyz-abc-testbed') @@ to_tsquery('abc')  # false

Then I realized that:

select to_tsvector('xyz-abc-testbed')
   to_tsvector
----------------------------------------------
'abc':3 'testb':4 'xyz':2 'xyz-abc-testb':1

But

select to_tsvector('xyz/xyz-abc-testbed')
   to_tsvector
----------------------------------------------
'xyz/xyz-abc-testbed':1

Looks like "/" impacts result of to_tsvector very much. But I don't find an explanation in PG documentation.

Please explain how '/' impacts tv_tsvector or point out some documentation that explains that. Thanks in advance.

1 Answers

The first step in full-text search processing is the parser, which splits the string in tokens and uses a heuristics to assign a type to them. Further processing depends on the type.

The function ts_debug is useful to analyze what is going on:

SELECT alias, description, lexemes
FROM ts_debug('xyz/xyz-abc-testbed');

 alias |    description    |        lexemes        
-------+-------------------+-----------------------
 file  | File or path name | {xyz/xyz-abc-testbed}
(1 row)

SELECT alias, description, lexemes
FROM ts_debug('xyz-abc-testbed');

      alias      |           description           |      lexemes      
-----------------+---------------------------------+-------------------
 asciihword      | Hyphenated word, all ASCII      | {xyz-abc-testbed}
 hword_asciipart | Hyphenated word part, all ASCII | {xyz}
 blank           | Space symbols                   | 
 hword_asciipart | Hyphenated word part, all ASCII | {abc}
 blank           | Space symbols                   | 
 hword_asciipart | Hyphenated word part, all ASCII | {testbed}
(6 rows)

PostgreSQL interprets a string with / in it as file path. It will not split a file path in parts, like it does with hyphenated words.

Related