首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQL响应中的不同结果数

问MySQL响应中的不同结果数
EN

Stack Overflow用户
提问于 2013-07-11 21:07:14
回答 1查看 29关注 0票数 0

在我的网站上有一个搜索表单,它根据搜索的单词顺序返回不同的结果。下面是两个搜索词的WHERE之后我继续查询的一部分:

代码语言:javascript
复制
(name_ru = '".words[0]."' or name_ru like '".words[0]."%' or name_ru like '% ".words[0]."%' or name_ru like '"".words[0]."%' or brief_description_ru like '%".words[0]."%' or product_code like '%".words[0]."%' or product_code in (select product_code from ALLPRODUCTS where searchfilter like '%".words[0]."%')) or product_code in (select product_code from SC_products prd JOIN SC_product_manufacturers mnf ON prd.manufacturerID=mnf.manufacturerID where mnf.filters like '%".words[0]."%') 
AND (name_ru = '".words[1]."' or name_ru like '".words[1]."%' or name_ru like '% ".words[1]."%' or name_ru like '"".words[1]."%' or brief_description_ru like '%".words[1]."%' or product_code like '%".words[1]."%' or product_code in (select product_code from ALLPRODUCTS where searchfilter like '%".words[1]."%')) or product_code in (select product_code from SC_products prd JOIN SC_product_manufacturers mnf ON prd.manufacturerID=mnf.manufacturerID where mnf.filters like '%".words[1]."%') 

当我改变这两个单词的顺序时,结果包含不同的行数。我应该怎么做才能每次都得到相同的结果,而不是依赖于单词的顺序呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-11 21:11:39

您应该考虑添加全文索引/使用全文搜索,而不是按照构建查询的方式进行查询。参见http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html。

全文搜索使用自然语言技术而不是特定的匹配来查看查询。如果您使用的是MyISAM表,则可以添加全文索引,但大多数表类型都允许在布尔模式下进行全文搜索。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17594220

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档