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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Java面试宝典4.0版

    Java面试宝典4.0版JAVA面试宝典V4.0版本基础1.简述JDK跟JRE的区别Jdk是java开发人员在开发过程使用的软件开发包,他提供了java的开发环境和运行环境JRE是JavaRuntimeEnviroment是指Java的运行环境如果你只想跑java程序,只要安装jre就够了,如果要从事开发就得安装jdk2.简述path跟classpat…

    2026年1月30日
    5
  • 关于Oracle的length函数问题

    关于Oracle的length函数问题提莫的Oracle的length函数不按常理出牌,length(”)返回的是null而不是0

    2022年5月8日
    61
  • 剑指Offer面试题:7.斐波那契数列

    一题目:斐波那契数列二效率很低的解法很多C/C++/C#/Java语言教科书在讲述递归函数的时候,大多都会用Fibonacci作为例子,因此我们会对这种解法烂熟于心上述递归的解法有很严重的效

    2021年12月19日
    39
  • 浮雕建模软件_自建房设计软件

    浮雕建模软件_自建房设计软件vectricaspire10是一款非常专业的3d浮雕模型设计软件,为CNC铣床上创建和切割零件提供了强大直观的解决方案,凭借其独特的3D组件建模、完善的2D设计、编辑工具集让你可以轻松使用现有2D数据或导入的3D模型,甚至能够从头开始创建自己的2D和3D零件。而且可以将几何体捕捉到不作为几何体存在的直线,延伸和交叉点,从而减少对大多数构造矢量的需求,还具有一整套完善的绘图工具,允许你通过在创建几何体时允许键入值来更轻松地为形状创建和编辑过程添加更多精度,让你能够更准确地切割这些形状。与此同时,全新的v

    2025年9月13日
    10
  • filetype all java试卷_java认证考试试题及答案

    filetype all java试卷_java认证考试试题及答案java认证考试试题及答案故答案为C。12.Whatistheresultafterthefollowingcodeexecutes?1shorts=0x00FD;2byteb=(byte)s;3System.out.println(b);Select1correctanswer:A.Compiletimeerrorinline1B.Comp…

    2022年7月8日
    26
  • 一场影响美国大选的战争利器:邮件安全+协作即时

    一场影响美国大选的战争利器:邮件安全+协作即时

    2022年3月4日
    32

发表回复

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

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