I am working on an app which is to suggest alternative words/phrases for input text. I have doubts about what might be a good design for the synonyms table.
Design considerations:
- number of synonyms is variable, i.e.
footballhas one synonym (soccer), butin particularhas two (particularly,specifically) - if
footballis a synonym tosoccer, the relation exists in the opposite direction as well. - our goal is to query a word and find its synonyms
- we want to keep the table small and make adding new words easy
What comes to my mind is a two column design with
col a = wordandcol b = delimited list of synonyms
Is there any better alternative? What about using two tables, one for words and the other for relations?
Edit:
After reading the answers, another approach came to my mind. It's using a single column table with all synonym words, each wrapped in word boundary marker. With that i mean something like
|in particular|particularly|specifically|
Then I'd query the table with
SELECT * FROM synonyms WHERE word LIKE '%|specifically|%'
And in code I trash the preceding and trailing |s and do a split and have the synonyms.
Anything bad in that, that I'm not seeing?