在php / mysql中搜索拼写错误的最佳方法是什么?

时间:2022-09-15 20:11:35

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%'.

如何让我的搜索脚本忽略这些错误?可能需要比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?

有人建议我使用全文搜索引擎,但所有这些看起来都非常复杂,我觉得将它们构建到我的应用程序中就像地狱一样。如果我必须使用一个,哪个是最不具侵入性的,那么在现有代码中实现最无痛苦?

3 个解决方案

#1


6  

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.

我认为你必须实现一个外部全文搜索引擎。 MySQL只是不擅长全文搜索。我会说你应该给Lucene一个去(教程)。 Zend Framework有一个插入Lucene的API,使其更容易学习和使用。

#2


1  

Presuming that you use MySQL - MySQL has no in-built functionality that is capable of doing this.

假设你使用MySQL - MySQL没有能够做到这一点的内置功能。

This means you will have to implement a full-text search yourself, or use a third party full text search tool.

这意味着您必须自己实施全文搜索,或使用第三方全文搜索工具。

  • If you implement it yourself, you should look into the metaphone or double metaphone algorithms (I'd recommend them over soundex, which is not nearly as good at this type of task), to store phoenetic representations of all your words. However, building your own full text search is no task for the faint-hearted. Don't attempt it if you don't consider yourself a database wizard.
  • 如果你自己实现它,你应该研究metaphone或双metaphone算法(我推荐它们超过soundex,这在这类任务上并不是那么好),以存储所有单词的phoenetic表示。但是,建立自己的全文搜索对于胆小的人来说不是任务。如果您不认为自己是数据库向导,请不要尝试它。

  • If you want a third party tool, Lucene is the way to go. It is ported into tons of different languages/platforms including PHP - you don't have to use Java.
  • 如果你想要第三方工具,Lucene就是你的选择。它被移植到许多不同的语言/平台,包括PHP - 您不必使用Java。

#3


0  

I've used neither php nor mysql, but an alternative to full text search might be soundex searches.

我既不使用php也不使用mysql,但是全文搜索的替代方法可能是soundex搜索。

#1


6  

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.

我认为你必须实现一个外部全文搜索引擎。 MySQL只是不擅长全文搜索。我会说你应该给Lucene一个去(教程)。 Zend Framework有一个插入Lucene的API,使其更容易学习和使用。

#2


1  

Presuming that you use MySQL - MySQL has no in-built functionality that is capable of doing this.

假设你使用MySQL - MySQL没有能够做到这一点的内置功能。

This means you will have to implement a full-text search yourself, or use a third party full text search tool.

这意味着您必须自己实施全文搜索,或使用第三方全文搜索工具。

  • If you implement it yourself, you should look into the metaphone or double metaphone algorithms (I'd recommend them over soundex, which is not nearly as good at this type of task), to store phoenetic representations of all your words. However, building your own full text search is no task for the faint-hearted. Don't attempt it if you don't consider yourself a database wizard.
  • 如果你自己实现它,你应该研究metaphone或双metaphone算法(我推荐它们超过soundex,这在这类任务上并不是那么好),以存储所有单词的phoenetic表示。但是,建立自己的全文搜索对于胆小的人来说不是任务。如果您不认为自己是数据库向导,请不要尝试它。

  • If you want a third party tool, Lucene is the way to go. It is ported into tons of different languages/platforms including PHP - you don't have to use Java.
  • 如果你想要第三方工具,Lucene就是你的选择。它被移植到许多不同的语言/平台,包括PHP - 您不必使用Java。

#3


0  

I've used neither php nor mysql, but an alternative to full text search might be soundex searches.

我既不使用php也不使用mysql,但是全文搜索的替代方法可能是soundex搜索。