Using ts_debug I can see what symbols Postgres treats as (what I call) a "word separator".


SELECT ts_debug('english', 'Hello. ABC')


(asciiword,"Word, all ASCII",Hello,{english_stem},english_stem,{hello})
(blank,"Space symbols",". ",{},,)
(asciiword,"Word, all ASCII",ABC,{english_stem},english_stem,{abc})

". " (dot space) is treated as a word separator. My problem is, I need Postgres to treat a single dot "." as a word separator too.

Right now, if I search for ABC no entry with the content Hello.ABC (without space after the dot) will be found, only with Hello. ABC.

I am using this search query:

SELECT description FROM incident WHERE
  to_tsvector('english', description) @@ to_tsquery('english', 'ABC')

Another example: Searching for IOException will not find java.io.IOException

Is there a way to treat a single dot (without space) as a word separator?

  • 3
    AFAIK you'll have to define your own dictionary for this. How easy it is I cannot tell, unfortunately. Alternatively, you could treat the periods without a space by adding one, and only apply to_tsvector() afterwards. It's a simple regexp_replace(), but might be costly. – dezso Aug 9 '16 at 9:07
  • 1
    That is a good workaround. I can add regexp_replace() to the index definition. So it's pretty fast! – Leif Aug 9 '16 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.