I have a Product
entity and table and would like the database design to allow finding a product by different keywords on top of its name, that is, like using a thesaurus e.g. product name "HDR-TD20V" should also be found by keywords "camcorder", "camera", "video camera", etc. Note that this same mechanics can be used to locate the same record from different input languages e.g. looking for "camara de video" (Spanish) or "videokamera" (German) should also find the same record.
Assuming that I am using Hibernate-search i.e. Lucene I have the following two design choices:
- De-normalized approach:
Product
table has akeywords
column that contain comma separated keywords for that product. This clearly violates the First Normal Form "... the value of each attribute contains only a single value from that domain.". However, this would integrate nicely with Hibernate-search. - Normalized approach: Define a
Keyword
entity table i.e.Keyword(id,keyword,languageId)
and the many-to-many associationProductKeyword(productId,keywordId)
but the integration with Hibernate-Search is not so intuitive anymore ... unless e.g. I create a materialized view i.e.select * from Product p, Keyword k, ProductKeyword pk where p.id=pk.productId and k.id=pk.keywordId
and index this materialized view.
I would of course prefer the choice 2 but I am not sure how Hibernate-search would optimally cover this use-case.