MySQL响应中的结果数量不同

时间:2013-07-11 13:07:14

标签: mysql where

我的网站上有搜索表单,它会在搜索的单词顺序上返回不同的结果。 以下是我的查询的一部分,在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]."%') 

当我更改这两个单词的顺序时,结果包含不同的行数。我应该怎么做才能得到每次相同的结果,这不取决于单词的顺序?

1 个答案:

答案 0 :(得分:0)

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

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

相关问题