dousi2553 2009-01-23 19:30 采纳率: 0%
浏览 21
已采纳

验证用户输入标签

I know this question might sound a little cheesy but this is the first time I am implementing a "tagging" feature to one of my project sites and I want to make sure I do everything right.

Right now, I am using the very same tagging system as in SO.. space seperated, dash(-) combined multiple words. so when I am validating a user-input tag field I am checking for

  1. Empty string (cannot be empty)
  2. Make sure the string doesnt contain particular letters (suggestions are welcommed here..)
  3. At least one word
  4. if there is a space (there are more than one words) split the string
  5. for each splitted, insert into db

I am missing something here? or is this roughly ok?

  • 写回答

4条回答 默认 最新

  • douzong5473 2009-01-24 00:25
    关注

    I've never implemented a tagging system, but am likely to do so soon for a project I'm working on. I'm primarily a database guy and it occurs to me that for performance reasons it may be best to relate your tagged entities with the tag keywords via a resolution table. So, for instance, with example tables such as:

    TechQuestion
    TechQuestionID (pk)
    SubjectLine
    QuestionBody

    TechQuestionTag
    TechQuestionID (pk)
    TagID (pk)
    Active (indexed)

    Tag
    TagID (pk)
    TagText (indexed)

    ... you'd only add new Tag table entries when never-before-used tags were used. You'd re-associate previously provided tags via the TechQuestionTag table entry. And your query to pull TechQuestions related to a given tag would look like:

    SELECT
    q.TechQuestionID,
    q.SubjectLine,
    q.QuestionBody
    FROM
    Tag t INNER JOIN TechQuestionTag qt
    ON t.TagID = qt.TagID AND qt.Active = 1
    INNER JOIN TechQuestion q
    ON qt.TechQuestionID = q.TechQuestionID
    WHERE
    t.TagText = @tagText
    

    ... or what have you. I don't know, perhaps this was obvious to everyone already, but I thought I'd put it out there... because I don't believe the alternative (redundant, indexed, text-tag entries) wouldn't query as efficiently.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持