英文:
design database for dictionary application
问题
我正在尝试制作一个字典应用程序,但在设计我的SQL数据库方面遇到了困难(我对数据库非常陌生)。
这是问题所在:
我想存储词条,词条可以是单词或句子。
一个词条可以有一个或多个定义。
如果我为一个单词“foo”创建一个词条,例如像这样:
词条:Foo
定义:Foo表示foobar bar
然后稍后我为“Bar”创建一个词条,例如像这样:
词条:Bar
定义:Bar表示lorem
我想要以某种方式连接所有先前具有词条“Bar”的定义,这种情况下是Foo,这样在我的前端中我可以在“Foo”的定义中放置一个链接到“Bar”的定义。换句话说,在将“Bar”插入数据库后,当我从数据库获取“Foo”的定义时,我还希望检索到“Bar”的ID,例如。
此外,词条可以由多个单词组成,但行为仍然相同。
英文:
I'm trying to make a dictionary application but having a hard time designing my sql database (I'm very new to databases).
Here's the problem:
I want to store entries, entires can be words or sentences.
An entry can have one or more definitions.
If I made an entry for a word foo
for example like so:
entry : Foo
Definitions: Foo means foobar bar
then later I made an entry for Bar
like so:
entry : Bar
Definition: Bar means lorem
I want someway to connect all previous definitons that had the entry Bar
, in this case Foo, so in my frontend I can put a link to Bar's
definition in Foo's
definiton. In other words after inserting Bar
into the database When I get Foo's definitons from the database I want to also retrieve Bar's Id for example.
also entries can consist of more than one word. but the behaviour will still be the same.
答案1
得分: 1
以下是翻译好的内容:
- 每次插入新条目时,您检查每个条目,看看它们中的哪些含有这个单词。如果您的数据库支持,您可以使用WHERE CONTAINS谓词来执行此操作,或者只需手动搜索每个条目。
- 在单词周围添加一个标记。例如,如果您要将"bar"添加到字典中,并找到了"foo"的一个条目,您可以将其定义更新为"Foo意味着foobar
bar "(我使用HTML,因为您提到了链接,但您可以使用适合您的任何内容)。
然后,当您尝试查找一个条目时,您可以解析定义并查找数据库中所需的条目。
英文:
The fastest way to do such a thing would be to:
- Each time you insert new entry, you check every entry to see which of them have this word. You can either do it with WHERE CONTAINS predicate, if your database supports it, or just manually search through every entry.
- Add a marker around the word. For example, you are adding bar into dictionary and found an entry in foo, you update its definition to "Foo means foobar <entry>bar</entry>" (I used HTML because you mentioned links, but you can use whatever is suitable for you)
Then when you trying to find an entry you would parse the definition and add links looking through the database for needed entries.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论