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


相关推荐

  • 艺赛旗胡立军:“机器人工厂”,让RPA风口再起

    艺赛旗胡立军:“机器人工厂”,让RPA风口再起艺赛旗胡立军:“机器人工厂”,让RPA风口再起

    2022年4月22日
    52
  • 学好R语言绘图,你只需这样一个网站就够了

    学好R语言绘图,你只需这样一个网站就够了你们是否有超级羡慕那些能做一手好图的人 俗语有云一图胜千言 做了一手好图很容易提升我们文章的逼格 所以我也常常在想 网络上有那种可视化的示例代码和示例效果图供我们参考学习的吗 目录 1 简单介绍 2 样例展示 2 1 词云 2 2 气泡图 3 总结话不多说 上网址 https www r graph gallery com r garp gallery 收入了大量利用 R 语言绘制的图形

    2026年3月19日
    2
  • html5十大新特性有哪些,HTML5有哪些新特性

    html5十大新特性有哪些,HTML5有哪些新特性摘要 HTML5 有哪些新特性考必过小编为大家整理了关于 HTML5 有哪些新特性的信息 希望可以帮助到大家 HTML5 有哪些新特性标签 定位绘图 group 页眉文档自动拖放包含正则表达 一 语义标签表示页面中一个内容区块或整个页面的标题 页面中的一个内容区块 如章节 页眉 页脚或页面的其他地方 可以和 h1 h2 元素结合起来使用 表示文档结构 表示

    2026年3月19日
    1
  • Consul + fabio 实现自动服务发现、负载均衡

    Consul + fabio 实现自动服务发现、负载均衡目录 ConsulFabio 服务发现的特点工作原理 Demo 结合 kubernetes 扩容 nbsp Consulhashic 团队开发就是大名鼎鼎开发 vagrant 的团队 Consul nbsp 是一个提供服务发现 健康检测 K V 存储支持分布式高可用多数据中心的服务软件 比较类似 ZooKeeper 但又比它多了一些功能 具体可以参考 nbsp Consul 和 ZooKeeper 的区别

    2026年3月19日
    2
  • 阿里云OpenClaw极简部署教程,打造专属AI助手!

    阿里云OpenClaw极简部署教程,打造专属AI助手!

    2026年3月13日
    2
  • 窗口分割

    我们在使用OutLook或者NetAnt等工具的时候,一般都会被其复杂的界面所吸引,在这些界面中窗口被分割为若干的区域,真正做到了窗口的任意分割。那么我们自己如何创建类似的界面,也实现窗口的任意的分

    2021年12月27日
    40

发表回复

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

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