mysql复数记录,如何在php mysql中搜索单数/复数

mysql复数记录,如何在php mysql中搜索单数/复数WhenIenterwo ex freshers Iwantfresher Mycodeislike search freshers qry mysql query selectcount fromj

mysql复数记录,如何在php mysql中搜索单数/复数

When I enter word (ex: freshers) I want fresher and freshers records both currently I am getting only freshers records. My code is like this:

$search=’freshers’;

$qry=mysql_query(“select count(*) from jobs where job_title like ‘%$search%’ or MATCH(job_title)

AGAINST(‘$search’ IN BOOLEAN MODE)”);

when the search word is freshers I m getting count as 1200. When the search word is fresher I am again getting count as 2000.

How to get almost same count when I enter either freshers or fresher.

解决方案

You cannot get precisely the same matching-record count from any MySQL technology with a search term that’s either singular or plural.

MySQL doesn’t have the smarts to know that freshers is the plural of fresher or children is the plural of child. If you want to do this with MySQL you’ll have to start your search with the singular form of the word for which you want the plural.

Neither does MySQL know that mice is the plural of mouse.

If you need automated plural/singular functionality you may want to investigate Lucene or some other natural language search tech. The name of the capability you seek is “stemming.”

But you can use FULLTEXT search with terms with trailing asterisks. For example, ‘fresher*’ matches fresher, freshers, and even fresherola. This will extend a search from singular to plural. It will not work the other way around. It

select count(*)

from jobs

where MATCH(job_title) AGAINST(‘fresher*’ IN BOOLEAN MODE)

There are some other modifying characters for boolean mode search terms. They are mentioned here:

Pro tip: column LIKE ‘%searchterm%’ is probably the slowest way MySQL offers to search a column. It is guaranteed to scan the whole table.

Pro tip: FULLTEXT search is inherently a bit fuzzy. Expecting crisp record counts from it is probably a path to confusion.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231418.html原文链接:https://javaforall.net

(0)
上一篇 2025年12月14日 下午2:01
下一篇 2025年12月14日 下午2:22


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号