postgres parsing whitespace before vectorizing Using PostgreSQL 11 to build a tsvector and create index for better search, and while trying to parse text, there is punctuation and/or whitespace characters that I need to handle differently than parser in PostgreSQL . 

For example, the term "R&amp;R" keeps getting separated and counted as two r's when I need "R&amp;R".

Also, another problematic string is "Main St./First St./Second St." which separates into "Main" "St./First"  and "St./Second".

I'm thinking the &amp; and / should be processed upstream of parsing punctuation, which I am just learning this stuff, so maybe it's easier than I am finding.

What is best approach?
You can create your own parser, but I think that doing so is unreasonably difficult.  Preprocessing the strings yourself before the parser gets called is probably the way to go.  You just need to make sure it is done consistently, for both tsvector and tsquery.  


  Also, another problematic string is "Main St./First St./Second St." which separates into "Main" "St./First" and "St./Second".


In my hands it is separated into './first', etc., not into 'st./first'.  Just preprocessing the '/' into ' ' should do the job of getting rid of the leading './', but will not do anything to make "First St." stay together as one unit if that is what you want  (If that is what you want, I don't know what the solution would be).

To make 'R&amp;R' stick together, you could just replace the '&amp;' with either '.' or '/'.  Both of those symbols are recognized as being part of file names or paths and so don't break up the words they come between (as long as there is not also some other whitespace/punctuation).

create function j(text) returns text immutable language SQL as $$ select translate($1,'&amp;/','/ ') $$;

select to_tsvector(j('The R&amp;R runs between First St./Second St.')) @@ plainto_tsquery(j('R&amp;R'));


This is all pretty grotty, and the 2 examples you give are unlikely to cover all special cases you will want to deal with.  And a more complete list will likely contain internal contradictions, like what if someone wrote 'Main St&amp;First St'?