我有两个表:食谱和标签,用于在CodeIgniter应用程序中进行全文搜索。对于每一个食谱,它们是无限数量的标签(标签的一些例子:美味,鸡肉,晚餐)。
配方表中的样例行:
菜谱Id: 1.....Recipe名称:莫氏鸡肉大餐.....
食谱Id: 2.....Recipe名称:莫氏龙虾汤.....
tags表中的样例行:
对应食谱Id: 1.....Tag: Tasty.....
对应食谱Id: 2.....Tag:海鲜.....
我希望能够搜索龙虾,并在搜索中显示与“龙虾”名称匹配的食谱。但我也想搜索“海鲜”,并有标签,有相应的食谱显示。
以下是我的代码(在添加join语句之前,它适用于一个表全文搜索):
// Execute our SQL statement and return the result
$sql = "SELECT recipes.name,recipes.durationtotal
FROM recipes LEFT JOIN tags ON recipes.id = tags.recipes_id
WHERE MATCH (recipes.name,tags.tag) AGAINST (?) > 0 AND user_id = ".$id." ORDER BY recipes.name ASC";
$query = $this->db->query($sql, array($terms, $terms));
return $query->result();在放入这段代码后,我得到了错误:
Error Number: 1210
Incorrect arguments to MATCH
SELECT recipes.name,recipes.durationtotal FROM recipes LEFT JOIN tags ON recipes.id = tags.recipes_id WHERE MATCH (recipes.name,tags.tag) AGAINST ('f') > 0 AND user_id = 1 ORDER BY recipes.name ASC
Filename: search_model.php
Line Number: 15第15行是:$query = $this->db->query($sql, array($terms, $terms));
感谢大家的帮助!
发布于 2013-02-24 10:16:42
如果搜索中涉及的所有表都不是MyISAM表,并且您还没有在要搜索的特定列集上设置全文索引,则匹配查询将失败。我认为,由于是针对不同表中的列进行搜索,因此不能创建跨两个表的全文索引。您可以在布尔模式下尝试:
MATCH (recipes.name,tags.tag) AGAINST (? IN BOOLEAN MODE)布尔模式比标准全文匹配更容易理解。
https://stackoverflow.com/questions/15047807
复制相似问题