I have data stored in mongodb collection - pages. Each page has following attributes:
title - string
id - number
contents - it is an object with 3 attribute
contents.topic - string
contents.parentTopic - number
contents.text - string
I have roughly 500 pages stored in DB and performance isn't a very big consideration for me.
I need to find common contents across all pages. If I do following:
$pages = $db->selectCollection("pages");
$cursor = $pages->find(array());
$data = array();
foreach ( $cursor as $page ){
array_push($data,$page);
}
$intersect = call_user_func_array('array_intersect_assoc',$data);
echo "<pre>";
print_r($intersect);
Like this I can get common contents across all pages which is working fine. This is true as long as there is at least one common 'content' across all pages.
But I need to find common sub-sets across all pages. For example, find the content that is common in pages 1-50, may be another subset that is common in pages 45,59,79,123,... another might be common in pages 450 - 459
Any better solution of finding such common sub-sets? Will it require creating trees?
Thanks.