1

I'm trying to find the similarities between two users of my application. I have tested the below query for just the interests attribute and it works fine:

SELECT interests FROM user WHERE uid=me() AND interests IN 
(SELECT interests FROM user WHERE uid = $targ_id)

I want to extend this to finding the similarities over the following attributes: movies, tv, music, books. Modifying the SELECT statements is trivial but I am unsure how to do the IN clause. This is what I tried doing:

    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)

This comes up with the following error:

{
  "error": {
    "message": "(#601) Parser error: unexpected ',' at position 82.",
    "type": "OAuthException",
    "code": 601
  }
}

How can I adjust this FQL query to make it work?

4

2 回答 2

2

我认为您无法使用 FQLIN运算符比较两个用户的兴趣。字段interests, movies,books等是字符串,而不是数组。您需要使用类似strpos()or的字符串操作substr()。FQL 没有LIKE操作。

您可以尝试编写一个巨大的 FQL 查询,在其中将每个结果用逗号分隔,然后将它们相互比较,但我认为将它们引入脚本并在后端执行此操作会容易得多。否则,您最终会遇到我的情况movies是“大白鲨,创世记”,而您的电影是“大白鲨,星球大战,创世记”,您将无法匹配,因为字符串不同。

于 2012-08-27T16:57:18.467 回答
0

您是否尝试过配置权限和扩展权限?

您的请求有错误。您不能在 close 中使用多个列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)
于 2012-08-27T16:06:03.147 回答