original_string: public function search(\stdClass $formdata, $limit = 0) {
          // For Behat testing, the search results can be faked using a special step.
          if (defined('BEHAT_SITE_RUNNING')) {
              $fakeresult = get_config('core_search', 'behat_fakeresult');
              if ($fakeresult) {
                  // Clear config setting.
                  unset_config('core_search', 'behat_fakeresult');
  
                  // Check query matches expected value.
                  $details = json_decode($fakeresult);
                  if ($formdata->q !== $details->query) {
                      throw new \coding_exception('Unexpected search query: ' . $formdata->q);
                  }
  
                  // Create search documents from the JSON data.
                  $docs = [];
                  foreach ($details->results as $result) {
                      $doc = new \core_search\document($result->itemid, $result->componentname,
                              $result->areaname);
                      foreach ((array)$result->fields as $field => $value) {
                          $doc->set($field, $value);
                      }
                      foreach ((array)$result->extrafields as $field => $value) {
                          $doc->set_extra($field, $value);
                      }
                      $area = $this->get_search_area($doc->get('areaid'));
                      $doc->set_doc_url($area->get_doc_url($doc));
                      $doc->set_context_url($area->get_context_url($doc));
                      $docs[] = $doc;
                  }
  
                  return $docs;
              }
          }
  
          $limitcourseids = $this->build_limitcourseids($formdata);
  
          $limitcontextids = false;
          if (!empty($formdata->contextids)) {
              $limitcontextids = $formdata->contextids;
          }
  
          // Clears previous query errors.
          $this->engine->clear_query_error();
  
          $contextinfo = $this->get_areas_user_accesses($limitcourseids, $limitcontextids);
          if (!$contextinfo->everything && !$contextinfo->usercontexts) {
              // User can not access any context.
              $docs = array();
          } else {
              // If engine does not support groups, remove group information from the context info -
              // use the old format instead (true = admin, array = user contexts).
              if (!$this->engine->supports_group_filtering()) {
                  $contextinfo = $contextinfo->everything ? true : $contextinfo->usercontexts;
              }
  
              // Execute the actual query.
              $docs = $this->engine->execute_query($formdata, $contextinfo, $limit);
          }
  
          return $docs;
      }
code: public function search(\stdClass $formdata, $limit = 0) {
          // For Behat testing, the search results can be faked using a special step.
          if (defined('BEHAT_SITE_RUNNING')) {
              $fakeresult = get_config('core_search', 'behat_fakeresult');
              if ($fakeresult) {
                  // Clear config setting.
                  unset_config('core_search', 'behat_fakeresult');
  
                  // Check query matches expected value.
                  $details = json_decode($fakeresult);
                  if ($formdata->q !== $details->query) {
                      throw new \coding_exception('Unexpected search query: ' . $formdata->q);
                  }
  
                  // Create search documents from the JSON data.
                  $docs = [];
                  foreach ($details->results as $result) {
                      $doc = new \core_search\document($result->itemid, $result->componentname,
                              $result->areaname);
                      foreach ((array)$result->fields as $field => $value) {
                          $doc->set($field, $value);
                      }
                      foreach ((array)$result->extrafields as $field => $value) {
                          $doc->set_extra($field, $value);
                      }
                      $area = $this->get_search_area($doc->get('areaid'));
                      $doc->set_doc_url($area->get_doc_url($doc));
                      $doc->set_context_url($area->get_context_url($doc));
                      $docs[] = $doc;
                  }
  
                  return $docs;
              }
          }
  
          $limitcourseids = $this->build_limitcourseids($formdata);
  
          $limitcontextids = false;
          if (!empty($formdata->contextids)) {
              $limitcontextids = $formdata->contextids;
          }
  
          // Clears previous query errors.
          $this->engine->clear_query_error();
  
          $contextinfo = $this->get_areas_user_accesses($limitcourseids, $limitcontextids);
          if (!$contextinfo->everything && !$contextinfo->usercontexts) {
              // User can not access any context.
              $docs = array();
          } else {
              // If engine does not support groups, remove group information from the context info -
              // use the old format instead (true = admin, array = user contexts).
              if (!$this->engine->supports_group_filtering()) {
                  $contextinfo = $contextinfo->everything ? true : $contextinfo->usercontexts;
              }
  
              // Execute the actual query.
              $docs = $this->engine->execute_query($formdata, $contextinfo, $limit);
          }
  
          return $docs;
      }
code_tokens: public function search ( \ stdClass $ formdata , $ limit = 0 ) { // For Behat testing, the search results can be faked using a special step. if ( defined ( 'BEHAT_SITE_RUNNING' ) ) { $ fakeresult = get_config ( 'core_search' , 'behat_fakeresult' ) ; if ( $ fakeresult ) { // Clear config setting. unset_config ( 'core_search' , 'behat_fakeresult' ) ; // Check query matches expected value. $ details = json_decode ( $ fakeresult ) ; if ( $ formdata -> q !== $ details -> query ) { throw new \ coding_exception ( 'Unexpected search query: ' . $ formdata -> q ) ; } // Create search documents from the JSON data. $ docs = [ ] ; foreach ( $ details -> results as $ result ) { $ doc = new \ core_search \ document ( $ result -> itemid , $ result -> componentname , $ result -> areaname ) ; foreach ( ( array ) $ result -> fields as $ field => $ value ) { $ doc -> set ( $ field , $ value ) ; } foreach ( ( array ) $ result -> extrafields as $ field => $ value ) { $ doc -> set_extra ( $ field , $ value ) ; } $ area = $ this -> get_search_area ( $ doc -> get ( 'areaid' ) ) ; $ doc -> set_doc_url ( $ area -> get_doc_url ( $ doc ) ) ; $ doc -> set_context_url ( $ area -> get_context_url ( $ doc ) ) ; $ docs [ ] = $ doc ; } return $ docs ; } } $ limitcourseids = $ this -> build_limitcourseids ( $ formdata ) ; $ limitcontextids = false ; if ( ! empty ( $ formdata -> contextids ) ) { $ limitcontextids = $ formdata -> contextids ; } // Clears previous query errors. $ this -> engine -> clear_query_error ( ) ; $ contextinfo = $ this -> get_areas_user_accesses ( $ limitcourseids , $ limitcontextids ) ; if ( ! $ contextinfo -> everything && ! $ contextinfo -> usercontexts ) { // User can not access any context. $ docs = array ( ) ; } else { // If engine does not support groups, remove group information from the context info - // use the old format instead (true = admin, array = user contexts). if ( ! $ this -> engine -> supports_group_filtering ( ) ) { $ contextinfo = $ contextinfo -> everything ? true : $ contextinfo -> usercontexts ; } // Execute the actual query. $ docs = $ this -> engine -> execute_query ( $ formdata , $ contextinfo , $ limit ) ; } return $ docs ; }
docstring: 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.
  
  Valid formdata options include:
  - q (query text)
  - courseids (optional list of course ids to restrict)
  - contextids (optional list of context ids to restrict)
  - context (Moodle context object for location user searched from)
  - order (optional ordering, one of the types supported by the search engine e.g. 'relevance')
  - userids (optional list of user ids to restrict)
  
  @param \stdClass $formdata Query input data (usually from search form)
  @param int $limit The maximum number of documents to return
  @return \core_search\document[]
docstring_tokens: Returns documents from the engine based on the data provided .