Question

I'm attempting to create a simple tool that will allow users to search through about 200 words by using synonyms defined by me.

Example: The word in the set is "fire". The user can search fire, flame, flames, matches, etc (I put these in)...and it will return "fire".

Initial Thoughts: My immediate thought was to just have a two column table, where the first column is the actual word, and the second column is an appropriate synonym:

ACTUAL             SYNONYM
fire               flame
fire               flames
fire               matches

So when the user searches, I would do a simple select:

SELECT actual WHERE synonym = "THE SEARCH TERM"

Question: How should I set up my database for searching these words and associate them with synonyms? Is my proposed solution the best/most efficient way? I feel like I ought to be able to have one row per "actual", and just put ALL synonyms in the second column, but I don't know how I would search this second column, or if it would even be more efficient than just a straight list.

Était-ce utile?

La solution

As long as your synonyms each map back to exactly one "actual" or core word, what you have is fine. Then it's just

select ACTUAL from Your_Table where SYNONYM = "The_Search_Term"

and you'll get back zero or one records.

I might use a like clause instead if your synonyms are dissimilar enough, so you don't need to mess with plurals:

select ACTUAL from Your_Table where SYNONYM like "%The_Search_Term%"

That way you don't need to include both flame and flames; flame will work for both.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top