1

There is a database of spare parts for cars, and online search by the name of spare parts. The user can type in the search, for example "safety cushion" or "airbag" - and the search result should be the same.

Therefore, I need somehow to implement the aliases for names of spare parts, and the question is how to store them in the database? Until now I have only one option that comes in mind - to create an additional table

| id | name of part   | alias_id |
-------------------------------------------------- ---------------
| 1  | airbag         | 10       |
| 2  | safety cushion | 10       |

And add additional field "alias_id" to table containing all the spare parts, and search by this field...

Are there other better options?

4

2 回答 2

0

Your solution looks fine for the exact problem you described.

BUT what if someone writes safetycushion? or safety cuschion? With these kinds of variations your alias lookup table will soon become huge and and manualy maintaining these will not be feasible.

At that point you'll need a completely different approach (think full text search engine).

So if you are still sure you only need a couple of aliases your approach seems to be fine.

于 2013-02-20T10:42:32.230 回答
0

If I have understood correctly, it's best to have 3 tables in a many to many situation (if multiple parts have multiple aliases:

Table - Parts

| id | name of part   |
-----------------------
| 1  | airbag         |
| 2  | safety cushion |

Table - Aliases

| id | name of alias  |
-----------------------
| 10 | AliasName      |

Table - PartToAliases

| id | PartId | AliasId |
-------------------------
| 1  | 1      | 10      |
| 2  | 2      | 10      |
于 2013-02-20T10:44:41.217 回答