/**
  * Transform the search request into a Status object representing the
  * search result. Varies based on CLI input argument `type`.
  *
  * @param string $query
  * @return Status<ResultSet>
  */
 protected function searchFor($query)
 {
     $searchType = $this->getOption('type', 'full_text');
     switch ($searchType) {
         case 'full_text':
             // @todo pass through $this->getConnection() ?
             $engine = new CirrusSearch($this->indexBaseName);
             $engine->setConnection($this->getConnection());
             $result = $engine->searchText($query);
             if ($result instanceof Status) {
                 return $result;
             } else {
                 return Status::newGood($result);
             }
         case 'prefix':
             $searcher = new Searcher($this->getConnection(), 0, 10, null, null, null, $this->indexBaseName);
             return $searcher->prefixSearch($query);
         case 'suggest':
             $searcher = new Searcher($this->getConnection(), 0, 10, null, null, null, $this->indexBaseName);
             $result = $searcher->suggest($query);
             if ($result instanceof Status) {
                 return $result;
             } else {
                 return Status::newGood($result);
             }
         default:
             $this->error("\nERROR: Unknown search type {$searchType}\n");
             exit(1);
     }
 }
 /**
  * Hooked to delegate prefix searching to Searcher.
  * @param int[] $namespaces namespace to search
  * @param string $search search text
  * @param int $limit maximum number of titles to return
  * @param array(string) $results outbound variable with string versions of titles
  * @param int $offset Number of results to offset
  * @return bool always false because we are the authoritative prefix search
  */
 public static function prefixSearch($namespaces, $search, $limit, &$results, $offset = 0)
 {
     $user = RequestContext::getMain()->getUser();
     $searcher = new Searcher(self::getConnection(), $offset, $limit, null, $namespaces, $user);
     if ($search) {
         $searcher->setResultsType(new FancyTitleResultsType('prefix'));
     } else {
         // Empty searches always find the title.
         $searcher->setResultsType(new TitleResultsType());
     }
     try {
         $status = $searcher->prefixSearch($search);
     } catch (UsageException $e) {
         if (defined('MW_API')) {
             throw $e;
         }
         return false;
     }
     // There is no way to send errors or warnings back to the caller here so we have to make do with
     // only sending results back if there are results and relying on the logging done at the status
     // constrution site to log errors.
     if ($status->isOK()) {
         if (!$search) {
             // No need to unpack the simple title matches from non-fancy TitleResultsType
             return $status->getValue();
         }
         $results = array();
         foreach ($status->getValue() as $match) {
             if (isset($match['titleMatch'])) {
                 $results[] = $match['titleMatch']->getPrefixedText();
             } else {
                 if (isset($match['redirectMatches'][0])) {
                     // TODO maybe dig around in the redirect matches and find the best one?
                     $results[] = $match['redirectMatches'][0]->getPrefixedText();
                 }
             }
         }
     }
     return false;
 }