我正在尝试在我的数据库中搜索“产品”、“描述”和“关键字”列。问题是,当我在表格的“描述”或“关键字”列中输入一个单词时,而不是在“产品”列中,它不会显示该结果。如果我在表格的“产品”列中键入一个单词,它只会显示结果。
我不确定 AND 语句是否在做我想要的。我想在这 3 列中搜索与用户搜索“类似”的单词,并按相关性对结果进行排序。任何帮助,将不胜感激。
$search_exploded = explode(" ",$searchquery);
foreach($search_exploded as $search_each)
{
$x++;
if ($x==1)
$construct .= "product LIKE '%$search_each%' AND description LIKE '%$search_each%' AND keywords LIKE '%$search_each%'";
else
$construct .= " OR product LIKE '%$search_each%' AND description LIKE '%$search_each%' AND keywords LIKE '%$search_each%'";
}
$sqlCommand = "SELECT * FROM Search WHERE $construct ORDER BY MATCH (product,description,keywords) AGAINST ('$searchquery') DESC";