when user write a article, i wanna automatically generate tags from user writes base on a existing tag list.
for example, i got a list like:
Manhattan
Brooklyn
Queens
….
if user write a article which contains these key words, it will come to the tags.
like user have title :”Today i skated in Manhattan”, then Manhattan should be include tags.
i had considered foreach the tag list, but it is very slow if the tag list come to a big size.
Do you guys have any solutions to automatically generate tags? or have any idea to implement this problem ?
thanks in advance.
Depending on the number of tags you have, a trie is likely to work well in this situation. With a trie, you build a tree data structure of the prefixes of your tags. For example, if you had tags like “A”, “to”, “tea”, “ted”, “ten”, “i”, “in”, and “inn” then you would build the following “prefix tree”:
In this tree, the “- character -” indicates an edge and “+ string +” indicates a node. Once you’ve built this trie, I imagine the following algorithm:
Read more trie data structures at Wikipedia: http://en.wikipedia.org/wiki/Trie