Advertisement
cmptrwz

tsvector fun

Sep 24th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. Concatinating TSVectors results in the index values starting from the highest of the left one + 1 for all atoms in the right one:
  2.  
  3. to_tsvector('keyword', 'the quick brown fox jumps over the lazy dog') || setweight(to_tsvector('simple', 'the quick brown fox jumps over the lazy dog'), 'A')
  4. results in
  5. 'brown':3,12A 'dog':9,18A 'fox':4,13A 'jump':5 'jumps':14A 'lazi':8 'lazy':17A 'over':6,15A 'quick':2,11A 'the':1,7,10A,16A
  6.  
  7. Building a new one as strings collapses them, so that each entry only shows up once per real position. However, the highest weight is the only one kept:
  8.  
  9. (to_tsvector('keyword', 'the quick brown fox jumps over the lazy dog')::text || ' ' || setweight(to_tsvector('simple', 'the quick brown fox jumps over the lazy dog'), 'A')::text)::tsvector
  10. results in
  11. 'brown':3A 'dog':9A 'fox':4A 'jump':5 'jumps':5A 'lazi':8 'lazy':8A 'over':6A 'quick':2A 'the':1A,7A
  12.  
  13.  
  14. The latter will, in theory, take up less space due to the lack of duplicated position information.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement