-6
我正在尝试通过单词相似性搜索,或者即使有人犯了错字。如何在MySQL中获得类似的搜索结果?
例如,如果有人用picadilly
进行搜索,那么正确的是piccadilly
,它应该得到结果。
我已经由去年移除一个字符,直到3个字符用PHP左,例如picadilly
picadill
picadil
picadi
picad
pica
pic
它的工作搜索尝试,但我也越来越不想要的结果(由于缩短关键字到3个字符)哪些不相似,也不要认为这是一个好方法,有没有更好的方法?
表结构&数据:
+----+---------------------------+------------------------------------------------------+
| id | name | address |
+----+---------------------------+------------------------------------------------------+
| 1 | Bethnal Green Station | Bethnal Green Tube Station, London, E2 0ET |
| 2 | Westminster Station | Westminster Tube Station, London, SW1A 2JR |
| 3 | Goldhawk Road Station | Goldhawk Road Tube Station, London, W12 8EG |
| 4 | Piccadilly Circus Station | Piccadilly Circus Tube Station, London, W1J 9HP |
| 5 | Ravenscourt Park Station | Ravenscourt Park Tube Station, London, W6 0JJ |
| 6 | Barons Court Station | Barons Court Tube Station, London, W14 9EA |
| 7 | Charing Cross Station | Charing Cross Tube & Train Station, London, WC2N 6RQ |
| 8 | Hammersmith Station | Hammersmith Tube Station, London, W6 8AB |
| 9 | Embankment Station | Embankment Tube Station, London, WC2N 6NS |
| 10 | Leicester Square Station | Leicester Square Tube Station, London, WC2H 0AP |
+----+---------------------------+------------------------------------------------------+
查询:
SELECT * FROM `stations`
WHERE name like '%picadilly%'
OR name like '%picadill%'
OR name like '%picadil%'
OR name like '%picadi%'
OR name like '%picad%'
OR name like '%pica%'
OR name like '%pic%'
感谢您的回应!但是,如何在此表格中添加通配符,比如我的表格字段包含“Piccadilly Circus Station”,我需要使用“picadilly” – 2014-09-11 10:10:56