The tsvector concatenation operator (tsvector || tsvector
), as the official documentation states, combines the lexemes and positional information of given vectors. Specifically:
Positions appearing in the right-hand vector are offset by the largest position mentioned in the left-hand vector
So this:
select 'one:10'::tsvector || 'two:5'::tsvector;
gives
'one':10 'two':15
But what if I need a larger offset between the concatenated phrases? Say, a 100. So it would be:
'one':10 'two':115
How can I achieve that?
One way would be to create a helper function to offset vectors positions. It can easily be implemented by using the same concatenation operator on a vector with a placeholder lexeme and a hardcoded position equal to the desired offset, and then deleting the placeholder lexeme from the resulting vector.
Now you can use it like this:
And get the desired result: