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条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效