在我的网站上有一个搜索表单,它根据搜索的单词顺序返回不同的结果。下面是两个搜索词的WHERE之后我继续查询的一部分:
(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]."%') 当我改变这两个单词的顺序时,结果包含不同的行数。我应该怎么做才能每次都得到相同的结果,而不是依赖于单词的顺序呢?
发布于 2013-07-11 21:11:39
您应该考虑添加全文索引/使用全文搜索,而不是按照构建查询的方式进行查询。参见http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html。
全文搜索使用自然语言技术而不是特定的匹配来查看查询。如果您使用的是MyISAM表,则可以添加全文索引,但大多数表类型都允许在布尔模式下进行全文搜索。
https://stackoverflow.com/questions/17594220
复制相似问题