Search code examples
sqlpostgresqlfull-text-search

Multiple synonym dictionary matches in full-text searching


I am trying to do full-text searching in PostgreSQL 8.3. It worked splendidly, so I added in synonym matching (e.g. 'bob' == 'robert') using a synonym dictionary. That works great too.

However, I've noticed that it apparently only allows a word to have one synonym. That is, al cannot be albert or allen.

Is this correct? Is there any way to have multiple dictionary matches in a PostgreSQL synonym dictionary?

For reference, here is my sample dictionary file:

bob    robert
bobby  robert
al     alan
al     albert
al     allen

And the SQL that creates the full text search config:

CREATE TEXT SEARCH DICTIONARY nickname (TEMPLATE = synonym, SYNONYMS = nickname);
CREATE TEXT SEARCH CONFIGURATION dxp_name (COPY = simple);
ALTER TEXT SEARCH CONFIGURATION dxp_name ALTER MAPPING FOR asciiword WITH nickname, simple;

Solution

  • That's a limitation in how the synonyms work. What you can do is turn it around as in:

    bob    robert
    bobby  robert
    alan   al
    albert al
    allen  al
    

    It should give the same end result, which is that a search for either one of those will match the same thing.