在php / mysql中将错字校正实施到搜索中的最佳方法是什么?(What's the best way to implement typo correction into a search in php/mysql?)

21 IT屋

I have a site that lists movies. Naturally people make spelling mistakes when searching for movies, and of course there is the fact that some movies have apostrophes, use letters to spell out numbers in the title, etc.

How do I get my search script to overlook these errors? Probably need something that's a little more intelligent than WHERE mov_title LIKE '%keyword%'.

It was suggested that I use a fulltext search engine, but all of those things look really complicated, and I feel that building them into my application will be like hell on earth. If I do have to use one, what's the least invasive one, that will be most painless to implement into existing code?

解决方案

I think you'll have to implement an external fulltext search engine. MySQL just isn't good at fulltext search. I'd say you should give Lucene a go (tutorials). Zend Framework has an API that plugs into Lucene, making it easier to learn and utilize.

我有一个列出电影的网站。人们自然会在搜索电影时犯拼写错误,并且当然存在一些电影带有撇号,使用字母来拼写标题中的数字等事实。



如何获得我的搜索脚本来忽略这些错误?可能需要比 WHERE mov_title LIKE'%keyword%'更聪明的东西。



我使用了全文搜索引擎,但是所有这些事情看起来真的很复杂,我觉得将它们构建到我的应用程序中将像人间地狱。如果我必须使用一种,那么侵入性最小的是什么,那么将其最容易实现到现有代码中?


解决方案

我认为您必须实现一个外部全文搜索引擎。 MySQL只是不擅长全文搜索。我想你应该给 Lucene 教程)。 Zend Framework有一个API 可以插入Lucene,从而更加容易学习和利用。


本文地址:IT屋 » 在php / mysql中将错字校正实施到搜索中的最佳方法是什么?