[英]SQL plural/singular searches
How can I make plural/singular words pull all forms? 如何将复数/单数词拉成所有形式?
Example: If a person searches for "mens rings" how can I check the data base to see if any of the fields contain mens, men, men's, ring, rings, etc.? 示例:如果某人搜索“男士戒指”,我如何查看数据库以查看是否有任何字段包含男士,男士,男士,戒指,戒指等?
It dosn't seem that using LIKE would be the best approach for what you need. 似乎使用LIKE似乎不是您需要的最佳方法。 I would look into MySQL FULLTEXT indexing to get the basic functionality working.
我会研究MySQL FULLTEXT索引以获得基本功能。 I'll have to look into the plural thing a bit more to see if that can be accomplished.
我将不得不更多地研究复数,看看是否可以实现。
Take a look at these two links for FULLTEXT indexing info. 看看FULLTEXT索引信息的这两个链接。
Here is a snippet from the second article: 以下是第二篇文章的片段:
SELECT headline, story FROM news
WHERE MATCH (headline,story) AGAINST ('Hurricane');
UPDATE: 更新:
I found this SO post in which a comment seems to suggest that the FULLTEXT indexing will take plural and grammatical forms into account but he dosn't cite a source, so it's hard for me to say for sure. 我发现这篇SO帖子中的评论似乎表明FULLTEXT索引会考虑复数和语法形式,但他没有引用来源,所以我很难肯定地说。 Can you try the FULLTEXT indexing method?
你能试试FULLTEXT索引方法吗?
The Sphinx full-text
search engine for MySQL handles such cases, and a few more (see here ). 用于MySQL的Sphinx
full-text
搜索引擎处理此类案例,还有一些(见此处 )。
It uses the Porter Stemmer algorithm [2] [3] to map things like "fishing", "fished", "fish", and "fisher" to a root stem of "fish" (see wiki ). 它使用Porter Stemmer算法 [2] [3]将诸如“钓鱼”,“钓鱼”,“鱼”和“渔夫”之类的东西映射到“鱼”的根茎(见维基 )。
select * from index_table where item_name rlike '[[:<:]]preform[s]*[es]*[ies]*[[:>:]]';
Check if this helps. 检查这是否有帮助。 My case it worked out.
我的情况很好。 Although will not cover for all plurals but yes for 90-95% cases.
虽然不会涵盖所有复数,但是90-95%的情况也是如此。
Cheers, Ashish 干杯,Ashish
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.