0

Given the following query:

select to_tsvector('fat cat ate rat') @@ plainto_tsquery('cats ate');

This query will return true as a result. Now, what if I don't want "cats" to also match the word "cat", is there any way I can prevent this?

Also, is there any way I can make sure that the tsquery matches the entire string in that particular order (e.g. the "cats ate" is counted as a single token rather than two). At the moment the following query will also match:

select to_tsvector('fat cat ate rat') @@ plainto_tsquery('ate cats');
agnsaft
  • 1,791
  • 7
  • 30
  • 49

1 Answers1

2

cat matching cats is due to english stemming, english being probably your default text search configuration. See the result of show default_text_search_config to be sure.

It can be avoided by using the simple configuration. Try the function calls with explicit text configurations:

select to_tsvector('simple', 'fat cat ate rat') @@ plainto_tsquery('simple', 'cats ate');

Or change it with:

set default_text_search_config='simple';
Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156
  • Thanks. Actually, I was looking into alternative dictionaries, but the documentation was not really clear on what (other) dictionaries were available and what their properties were. I will definitely try this dictionary. – agnsaft Apr 23 '13 at 20:20
  • Do you know how to increase precision of the matching further by making 'fat cat' count as a single token rather than two? – agnsaft Apr 23 '13 at 20:26
  • @invictus: I don't see how the parser could be tweaked to group words. If you want phrase search it's not implemented but that can be worked around more or less, see [this related question](http://stackoverflow.com/questions/1489617). – Daniel Vérité Apr 24 '13 at 10:51