dqotv26286 2014-04-28 10:29
浏览 165
已采纳

在php sql数据库中搜索同义词

I am searching for string in mysql database in php,which i m doing with like keyword.The problem is when i am having synonyms entered from user.Like in the database i m having all the products with the name shoes,and user enters footwear or some mismatched words.how to search for these different conditions.. Please guide on this.

Currently i m using following select query

Select * from table where name like '%user entered string%'

Please guide on how to tackle these conditions

  • 写回答

2条回答 默认 最新

  • dongmaonao0505 2014-04-28 10:57
    关注

    Let's sum it up.

    Let's assume that you have a table products which, I highly assume and hope, consists of products with unique ids.

    products
    
    id     product
    1      Shoes
    2      Trousers
    

    And so on. If you were to add an another column, let's say, synonyms, it would look something like this:

    products
    
    id     product    synonyms
    1      Shoes      Footwear, stuff on feet, 
    2      Trousers   
    

    We don't want this. You'd have to select the synonyms column, parse the string and make sure you don't ruin the column when you somehow wish to add new synonyms to each product.

    It makes much more sense to have an atomic database where you'd have a table of synonyms where each synonym references a unique id in your products table, this way it's easy to delete old synonyms and add new ones.

    products
    
    id     product
    1      Shoes
    2      Trousers
    
    synonyms
    id     product_id     synonym
    1      1              Footwear
    2      1              stuff on feet
    

    You can then look up in this table if the original select like statement fails.

    Using an external data-source is also a possibility but this is probably the most suitable way to go if you want to control the flow and avoid external sources.

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

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记