PHP MySQL 搜索建议

发布于 2024-12-01 11:16:53 字数 275 浏览 1 评论 0原文

在我的网络应用程序中将有多个用户。他们有自己的内容上传到我的网络应用程序。他们上传的每个内容都有标题、描述和标签(关键词)。我可以编写一个搜索脚本来搜索内容或用户名。但是当他们给出拼写错误的关键字时,它不会返回任何结果。例如,如果数据库中有一个名为“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北城孤痞 2024-12-08 11:16:53

您可以使用 SOUNDEX 搜索听起来相似的名称,如下所示:

SELECT * FROM users WHERE SOUNDEX(name) = SOUNDEX(:input)

或类似

SELECT * FROM users WHERE name SOUNDS_LIKE :input

(完全等效)

编辑:如果您需要使用 Soundex 以外的算法,正如 Martin Hohenberg 建议的那样,您需要添加一个额外的列到您的表,例如称为 sound_equivalent。 (这实际上是一个更有效的解决方案,因为该列可以建立索引)。那么请求将是:

SELECT * FROM users WHERE sound_equivalent = :input_sound_equivalent

sound_equivalent 列的内容可以使用 PHP 算法生成,并与其余用户参数一起插入到表中。

You could use SOUNDEX to search for similar-sounding names, like that:

SELECT * FROM users WHERE SOUNDEX(name) = SOUNDEX(:input)

or like that

SELECT * FROM users WHERE name SOUNDS_LIKE :input

(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:

SELECT * FROM users WHERE sound_equivalent = :input_sound_equivalent

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.

北凤男飞 2024-12-08 11:16:53

如果您没有,您还可以使用 php 库 pspell 获取建议搜索结果。

You can also use the php library pspell to get suggestions if you have no search results.

终止放荡 2024-12-08 11:16:53

也许创建一个最常见单词的数据库(例如:狗、房子、城市、数字、水、互联网)。不需要太大(<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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文