2009-03-23

Confuse with text search

One expect true here, but result is dissapointing false

postgres=# select to_tsquery('ob_1','inferences') @@
to_tsvector('ob_1','inference');
 ?column? 
----------
 f
(1 row)

We can use ts_debug function to understand the problem

postgres=# select * from ts_debug('ob_1','inferences'); 
   alias   |   description   |   token    |        dictionaries         | dictionary  |  lexemes   
-----------+-----------------+------------+-----------------------------+-------------+------------
 asciiword | Word, all ASCII | inferences | {french_ispell,french_stem} | french_stem | {inferent}
(1 row)
postgres=# select * from ts_debug('ob_1','inference'); 
   alias   |   description   |   token   |        dictionaries         |  dictionary   |   lexemes   
-----------+-----------------+-----------+-----------------------------+---------------+-------------
 asciiword | Word, all ASCII | inference | {french_ispell,french_stem} | french_ispell | {inference}
(1 row)

Now, we see that real problem is that french_ispell doesn't recognized plural form of word 'inference' (ispell and stemmer stem word 'inferences' differently, which is ok ).

What to do ? The best way is to teach ispell dictionary, the easiest way is to use synonym dictionary and put it first in the stack of dictionaries:

inferences inference

And don't forget to reindex !

btw, another way is to use ts_rewrite, so you don't need to reindex.