/** * Returns documents from the engine based on the data provided. * * This function does not perform any kind of security checking, the caller code * should check that the current user have moodle/search:query capability. * * It might return the results from the cache instead. * * @param stdClass $formdata * @param int $limit The maximum number of documents to return * @return \core_search\document[] */ public function search(\stdClass $formdata, $limit = 0) { global $USER; $limitcourseids = false; if (!empty($formdata->courseids)) { $limitcourseids = $formdata->courseids; } // Clears previous query errors. $this->engine->clear_query_error(); $areascontexts = $this->get_areas_user_accesses($limitcourseids); if (!$areascontexts) { // User can not access any context. $docs = array(); } else { $docs = $this->engine->execute_query($formdata, $areascontexts, $limit); } return $docs; }
/** * Returns documents from the engine based on the data provided. * * This function does not perform any kind of security checking, the caller code * should check that the current user have moodle/search:query capability. * * It might return the results from the cache instead. * * @param stdClass $formdata * @return \core_search\document[] */ public function search(\stdClass $formdata) { $cache = \cache::make('core', 'search_results'); // Generate a string from all query filters // Not including $areascontext here, being a user cache it is not needed. $querykey = $this->generate_query_key($formdata); // Look for cached results before executing it. if ($results = $cache->get($querykey)) { return $results; } // Clears previous query errors. $this->engine->clear_query_error(); $areascontexts = $this->get_areas_user_accesses(); if (!$areascontexts) { // User can not access any context. $docs = array(); } else { $docs = $this->engine->execute_query($formdata, $areascontexts); } // Cache results. $cache->set($querykey, $docs); return $docs; }