public function getSearchResultsCriteria(vB_Search_Criteria $criteria, $searchType) { //first let's see if this is valid. $userdata = vB::getUserContext()->getReadChannels(); if (empty($userdata['canRead']) and empty($userdata['selfOnly'])) { throw new vB_Exception_Api('no_permission'); } $json = $criteria->getJSON(); $results = array(); $records_nr = 0; $time_before = $time_after = microtime(true); if ($searchType == self::SEARCH_TYPE_USER) { // user requested this search, so we need to check flooding vB_Search_Core::instance()->floodCheck(); } if (empty($json['error'])) { $results = vB_Search_Core::instance()->getResults($criteria); $time_after = microtime(true); } $return_structure = vB_Search_Core::instance()->cacheResults($results, $criteria, $time_after - $time_before, $searchType); /**need to duplicate the cache so it can be picked up in case the custom field is not provided. * having a custom field generated a different hash but has the same results */ if (!empty($json['custom'])) { unset($json['custom']); $criteria->setJSON($json); vB_Search_Core::instance()->cacheResults($results, $criteria, $time_after - $time_before, $searchType); } $return_structure['ignored_keywords'] = $criteria->get_ignored_keywords(); $return_structure['totalRecords'] = count($results); return $return_structure; }
/** * Generate a cache key for the first pass of getSearchResults. Build key based on: * usergroupids, infractiongroupids, search json, search sort order, search sort by, * moderated channels * * @param vB_Search_Criteria * * @staticvar array $hashResult Array to build hash from * @return string */ public static function getTwoPassCacheKey(vB_Search_Criteria $criteria) { $cacheTTL = vB_Api_Search::getCacheTTL(); if ($cacheTTL < 1) { return false; } $channelAccess = vB::getUserContext()->getAllChannelAccess(); $currentUserId = vB::getCurrentSession()->get('userid'); // Don't use cache if we have a GIT record if (!empty($channelAccess['member'])) { return false; } // Not 100% set on this but it seems adding further nodes to the result set // could introduce nodes that were grabbed based on nodes that might // end up removed on the second pass if ($criteria->get_post_processors()) { return false; } $json = $criteria->getJSON(); //$json['disable_two_pass'] = true; if (!empty($json['disable_two_pass']) or !empty($json['my_following']) and !empty($currentUserId) or !empty($json[vB_Api_Search::FILTER_FOLLOW]) or !empty($json['private_messages_only']) or !empty($json['include_private_messages']) or !empty($json['date']) and $json['date'] == vB_Api_Search::FILTER_LASTVISIT or !empty($json['unread_only']) or !empty($json['author']) and !empty($json['exactname']) and ($json['author'] == 'myFriends' or $json['author'] == 'iFollow')) { return false; } // Don't cache for globally ignored users if (!empty($currentUserId)) { $globalignore = trim(vB::getDatastore()->getOption('globalignore')); if (!empty($globalignore)) { $blocked = preg_split('#\\s+#s', $globalignore, -1, PREG_SPLIT_NO_EMPTY); $bbuserkey = array_search($currentUserId, $blocked); if ($bbuserkey !== FALSE and $bbuserkey !== NULL) { return false; } } } if (isset($json['ignored_words'])) { unset($json['ignored_words']); } if (isset($json['original_keywords'])) { unset($json['original_keywords']); } // Make sure ugids and ifids are in a consistent order $ugids = $ifids = $mod = ''; $userinfo = vB_User::fetchUserinfo(); if (!empty($userinfo['membergroupids']) and trim($userinfo['membergroupids']) != '' and $ugids = explode(',', str_replace(' ', '', $userinfo['membergroupids']))) { $ugids[] = $userinfo['usergroupid']; sort($ugids, SORT_NUMERIC); $ugids = array_unique($ugids, SORT_NUMERIC); $ugids = implode(',', $ugids); } else { $ugids = $userinfo['usergroupid']; } $ifid = !empty($userinfo['infractiongroupid']) ? intval($userinfo['infractiongroupid']) : 0; if (!empty($userinfo['infractiongroupids']) and trim($userinfo['infractiongroupids']) != '' and $ifids = explode(',', str_replace(' ', '', $userinfo['infractiongroupids']))) { if ($ifid) { $ifids[] = $ifid; } sort($ifids, SORT_NUMERIC); $ifids = array_unique($ifids, SORT_NUMERIC); $ifids = implode(',', $ifids); } else { if ($ifid) { $ifids = $ifid; } } if (!empty($channelAccess['canmoderate'])) { $mod = $channelAccess['canmoderate']; sort($mod, SORT_NUMERIC); $mod = array_unique($mod, SORT_NUMERIC); $mod = implode(',', $mod); } $hashResult = array('json' => $json, 'so' => $criteria->get_sort_field(), 'sb' => $criteria->get_sort_direction(), 'ul' => vB::getUserContext()->getUserLevel(), 'ug' => $ugids); if (!empty($ifids)) { $hashResult['if'] = $ifids; } if (!empty($mod)) { $hashResult['mod'] = $mod; } return 'getSearchResults_' . md5(serialize($hashResult)); }