我正试图找到我的应用程序的两个用户之间的相似之处。我已经测试了下面的查询只是兴趣属性,它工作正常:
SELECT interests FROM user WHERE uid=me() AND interests IN
(SELECT interests FROM user WHERE uid = $targ_id)
我想扩展这个以找到与以下属性的相似之处:movies, tv, music, books
。修改SELECT
语句是微不足道的,但我不确定如何执行IN
子句。这就是我尝试做的事情:
SELECT interests, movies, tv, music, books FROM user WHERE uid=me()
AND (interests, movies, tv, music, books) IN
(SELECT interests, music, tv, movies, books FROM user WHERE uid = $targ_id)
这会出现以下错误:
{
"error": {
"message": "(#601) Parser error: unexpected ',' at position 82.",
"type": "OAuthException",
"code": 601
}
}
如何调整此FQL查询以使其正常工作?
答案 0 :(得分:2)
我认为您无法使用FQL IN
运算符比较两个用户的兴趣。字段interests
,movies
,books
等是字符串,而不是数组。您需要使用strpos()
或substr()
之类的字符串操作。 FQL没有LIKE
操作。
您可以尝试编写一个巨大的FQL查询,在其中将每个结果拆分为逗号,并将它们相互比较,但我认为将这些内容添加到您的脚本并在后端。否则你最终会遇到我的movies
是“Jaws,Tron”和你的电影是“大白鲨,星球大战,Tron”的情况,你不会有匹配,因为字符串是不同的。
答案 1 :(得分:0)
您是否尝试过配置权限和扩展权限?
您的请求有错误。您无法在关闭AND
中使用多个列。也许你应该试试这个:
SELECT interests, movies, tv, music, books FROM user
WHERE uid=me()
AND (interests) IN (SELECT interests FROM user WHERE uid = $targ_id)
AND (movies) IN (SELECT movies FROM user WHERE uid = $targ_id)
AND (tv) IN (SELECT tv FROM user WHERE uid = $targ_id)
AND (music) IN (SELECT music FROM user WHERE uid = $targ_id)