当我从流表中提取搜索结果时,返回的其中一个组件是一个注释数组。我想知道是否有任何基于评论数组中评论文本的搜索方式?
这是我的查询。它目前的形式很好:
SELECT post_id, attribution, message, description, comments.comment_list.text, likes, place, permalink, message_tags, message, description_tags, type FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me()) AND ( (strpos(lower(message), 'college football') >= 0) OR (strpos(lower(description), 'college football') >= 0) OR (strpos(lower(attribution), 'college football') >= 0) ) order by created_time desc
其中一个返回行的 comments.comment_list.text 结果如下所示:
"comments": { "comment_list": [ { "text": "I love college football" }, { "text": "Alabama and LSU rule college football" } ] }
我的问题是:我是否有办法以与消息相同的方式搜索 comments.comment_list.text ,上面的描述和归因?当我尝试添加如下内容时:
(strpos(lower(comments.comment_list.text), 'college football') >= 0)
我有一个空数据集(有趣的是,我没有得到任何错误,只是空结果)。我可以看到原因,因为我需要以某种方式能够遍历注释数组,然后检索它们的文本并对注释文本进行比较。我想在Facebook端使用FQL执行此操作,并希望避免检索所有结果,然后在我的结尾迭代它们。关于我如何能够做到这一点的任何想法或建议?
提前感谢您的帮助!
答案 0 :(得分:2)
comments
表中的stream
字段仅检索注释的子集。我认为限制是5.那么,搜索FQL返回的数组似乎应该很容易。事实并非如此。
最好的办法是将其转换为多重查询。要获得结果,您只需查看#combined
数据。
{'all_posts':
'SELECT post_id FROM stream WHERE filter_key in
(SELECT filter_key FROM stream_filter WHERE uid=me())',
'commented':
'SELECT post_id FROM comment WHERE post_id IN (SELECT post_id FROM #all_posts)
AND (strpos(lower(text), 'college football') >= 0',
'combined':
'SELECT post_id, attribution, message, description, comments.comment_list.text, likes,
place, permalink, message_tags, message, description_tags, type
FROM stream WHERE post_id IN (SELECT post_id FROM #all_posts) AND
(
(strpos(lower(message), 'college football') >= 0) OR
(strpos(lower(description), 'college football') >= 0) OR
(strpos(lower(attribution), 'college football') >= 0)
)
OR post_id IN (SELECT post_id FROM #commented)
order by created_time desc'
}