Reputation: 5653
Is it a good idea to have a 'search table'?
For example, a search that can search 'users', 'groups' and 'pages' (Facebook style) would have fields like keywords, userid, groupid, and pageid.
That way the system can do a LIKE query on the keywords from one table.
Or would it be better like
keyword1, keyword2, keyword3, keyword4, keyword5, userid, groupid, pageid
or
keeping the keywords in each of the tables (user, group and page)... But I am quite sure I will not need the keywords for anything else than searching.
Upvotes: 1
Views: 867
Reputation: 332571
I recommend using the following table setup:
STUFF_TYPE_CODE
tableSTUFF_TYPE_CODE
, pkSTUFF_TYPE_DESCRIPTION
--IE: users, groups, pages, etc...STUFF_KEYWORD_XREF
tableSTUFF_ID
, pkKEYWORD_ID
, pkSTUFF_TYPE_CODE
, pk, fkKEYWORDS
table:KEYWORD_ID
, pkKEYWORD_DESCRIPTION
This setup will let you:
All three columns in the STUFF_KEYWORD_XREF
table need to be the primary key to ensure that there aren't duplicates based on all three values.
Upvotes: 3