MySQL MATCH-AGAINST 复数单词?

发布于 2024-11-04 03:23:01 字数 555 浏览 1 评论 0原文

我想向我的网站添加搜索。我有一个视频游戏挑战数据库。每个挑战都有标题和描述,我希望至少能够搜索描述,但如果可能的话,两者都搜索。现在,我已经设置了表格,以便可以使用 MATCH() AGAINST(),但我遇到了单数或复数单词的问题。

例如,“assists”这个词出现在多个挑战中,但如果用户输入“assist”,他将不会得到任何东西。有什么方法可以添加该功能吗?我已经尝试了我能想到的一切,但到目前为止没有任何效果。

更新:我最近才了解 MATCH AGAINST,所以我不确定在我的案例中使用它的“正确”方法。就像我说的,我有一个表,其中有一个名为 description 的列,使用上面的示例单词 assists,它在表中出现多次,我会使用这个查询:

SELECT * FROM challenges WHERE MATCH(description) AGAINST('assists')

我刚刚执行了它,它返回了 10 行。如果我将其更改为 assist,我什么也得不到。

I'd like to add a search to my site. I have a database of challenges from a video game. Each challenge has a title and description, I'd like to be able to search at least the description, but both if possible. Now, I've set the table up so that I can use MATCH() AGAINST(), but I'm having a problem with words that can be either singular or plural.

For example, the word "assists" appears in multiple challenges, but if the user types "assist", he won't get anything. Is there any way that I can add that functionalty? I've tried everything I can think of, but nothing has worked so far.

Update: I only just recently learned about MATCH AGAINST, so I'm not sure the "right" way to use it in my case. Like I said, I've got a table with a column called description, using the example word from above, assists, which appears multiple times in the table, I would use this query:

SELECT * FROM challenges WHERE MATCH(description) AGAINST('assists')

I just executed that and it returned 10 rows. If I change it to assist, I get nothing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

温柔戏命师 2024-11-11 03:23:01

也许您可以使用 MySQL 中的 SOUNDEX() 函数。

SELECT
  id,
  title
FROM products AS p
WHERE p.title SOUNDS LIKE 'Shaw'

// This wil match 'Saw' etc.

我认为这也可能适用于你,他会用复数

Maybe you can use the SOUNDEX() function from MySQL.

SELECT
  id,
  title
FROM products AS p
WHERE p.title SOUNDS LIKE 'Shaw'

// This wil match 'Saw' etc.

I think this also may be applicable for you and that he will take with plurals

旧情别恋 2024-11-11 03:23:01

我可能错过了你想要做的事情的要点,但为什么不直接做这样的 LIKE 匹配:

SELECT * FROM challenges WHERE description LIKE "%assist%";

它将匹配任何包含“assist”和“assists”的内容。当然它也会匹配“助理”和“协助”,这可能不是你想要的......

I might be missing the point of what you're trying to do, but why not just do a LIKE match like this:

SELECT * FROM challenges WHERE description LIKE "%assist%";

That will match anything that contains "assist" as well as "assists". Of course it will also match "assistant" and "assistance", which may not be what you want...

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