PHP MySQL 搜索建议
在我的网络应用程序中将有多个用户。他们有自己的内容上传到我的网络应用程序。他们上传的每个内容都有标题、描述和标签(关键词)。我可以编写一个搜索脚本来搜索内容或用户名。但是当他们给出拼写错误的关键字时,它不会返回任何结果。例如,如果数据库中有一个名为“Michael”的用户,并且搜索查询是“Micheal”,我应该得到“您是否打算搜索“Michael””,这只不过是一个搜索建议。
此建议也应该针对用户上传的内容。用户可以将其内容的标题保留为“Michael 2011 年 5 月的活动”,并且应该针对各个单词生成建议。
In my web application there will be several users. and they have their own contents uploaded to my webapp. For each content they upload it has a title, description and tags(keywords). I can write a search script to search for content or user name. but they keywords when they have given with a spelling mistake it doesn't return any result. For example if there is a user named "Michael" in the database and the search query was "Micheal" i should get "Did you mean to search for 'Michael'" which is none other than a search suggestion.
Also this suggestion should be for the contents uploaded by the user. An user may keep their content's title as "Michael's activities May 2011" and suggestions should be generated for individual words.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 SOUNDEX 搜索听起来相似的名称,如下所示:
或类似
(完全等效)
编辑:如果您需要使用 Soundex 以外的算法,正如 Martin Hohenberg 建议的那样,您需要添加一个额外的列到您的表,例如称为 sound_equivalent。 (这实际上是一个更有效的解决方案,因为该列可以建立索引)。那么请求将是:
sound_equivalent 列的内容可以使用 PHP 算法生成,并与其余用户参数一起插入到表中。
You could use SOUNDEX to search for similar-sounding names, like that:
or like that
(which is completely equivalent)
Edit: if you need to use an algorithm other than Soundex, as Martin Hohenberg suggested, you would need to add an extra column to your table, called, for example, sound_equivalent. (This is actually a more efficient solution as this column can be indexed). The request would then be:
The content of the sound_equivalent column can then be generated with a PHP algorithm, and inserted in the table with the rest of user parameters.
如果您没有,您还可以使用 php 库 pspell 获取建议搜索结果。
You can also use the php library pspell to get suggestions if you have no search results.
也许创建一个最常见单词的数据库(例如:狗、房子、城市、数字、水、互联网)。不需要太大(<10000字)。
然后,当您展开搜索词时,请检查“单词”数据库中是否有类似于搜索词的单词。然后只是回应建议。
Maybe create a database of the most common words (like: dog, house, city, numbers, water, internet). Don't need to make it big (<10000 words).
Then when you explode the search term, check the "word" database for words LIKE the search terms. Then just echo out the suggestions.