Finds all commands that match the search string.
@param string   $searchString
@param bool     $exact         Whether the search should be exact.
@return \CharlotteDunois\Livia\Commands\CommandGroup[]
972703
function findGroups(string $searchString, bool $exact = false) {
        $searchString = \mb_strtolower($searchString);
        if(\mb_strpos($searchString, ':') !== false) {
            $parts = \explode(':', $searchString);
            $searchString = \array_pop($parts);
        }
        
        $matches = array();
        foreach($this->groups as $group) {
            if($exact) {
                if($group->id === $searchString || \mb_strtolower($group->name) === $searchString) {
                    $matches[] = $group;
                }
            } else {
                if(\mb_stripos($group->id, $searchString) !== false || \mb_stripos($group->name, $searchString) !== false) {
                    $matches[] = $group;
                }
            }
        }
        
        if($exact) {
            return $matches;
        }
        
        foreach($matches as $group) {
            if($group->id === $searchString || \mb_strtolower($group->name) === $searchString) {
                return array($group);
            }
        }
        
        return $matches;
    }
1138917
public function compareCommandName($commandName, $search) {
        $commandName = preg_split('/(:|-|_)/', $commandName);
        $search = preg_split('/(:|-|_)/', $search);

        foreach ($search as $index => $searchPart) {
            $stringPart = array_get($commandName, $index);

            if ($stringPart === null) {
                return false;
            }

            if ( ! str_starts_with($stringPart, $searchPart)) {
                return false;
            }
        }

        return true;
    }
588240
protected function autocomplete(string $partialCommand, int $index): array
    {
        // @TODO Add more functionality by parsing the current buffer with readline_info()
        // @TODO Filter file system elements (if possible at all)

        $suggestions = [];

        $availableCommands = $this->bootstrap->getObjectManager()
            ->get(CommandManager::class)
            ->getAvailableCommands();

        /** @var $command Command */
        foreach ($availableCommands as $command) {
            if ($command->isInternal() === false) {
                $suggestions[] = $command->getCommandIdentifier();
            }
        }

        return $suggestions;
    }
860992
public function search(array $types, array $query, array $queryStringParams = [])
    {
        $params = [];
        $params['index'] = $this->getIndexName();
        
        $resolvedTypes = [];
        foreach ($types as $type) {
            $resolvedTypes[] = $this->resolveTypeName($type);
        }
        
        if (!empty($resolvedTypes)) {
            $params['type'] = implode(',', $resolvedTypes);
        }
        
        $params['body'] = $query;

        if (!empty($queryStringParams)) {
            $params = array_merge($queryStringParams, $params);
        }

        $this->stopwatch('start', 'search');
        $result = $this->client->search($params);
        $this->stopwatch('stop', 'search');

        return $result;
    }
1337180
protected function searchCommand(string $name):array
    {
        $f = $this->fileCommand;
        $finalC = array();
        if ($f == null) {
            throw new Server500(new \ArrayObject(array("explain" =>
                "Framework Console Arguments Error : Command File is empty",
                "solution" => "Command file not be empty")));
        }
        $commands = $f->commands;

        foreach ($commands as $command => $val) {
            if ($val->type === "single") {
                if ($command == $name) {
                    return (array("name" => $command, "class" => $val->class, "desc" => $val->desc));
                }
            } elseif ($val->type === "multiple") {
                foreach ($val->args as $aval) {
                    if ($aval->name === $name) {
                        return (array("name" => $aval->name, "class" => $val->class, "desc" => $aval->desc));
                    }
                }
            } else {
                throw new Server500(new \ArrayObject(array("explain" => "Undefined command type [".$val->type."]",
                    "solution" => "Please set a valid command type [single, multiple]")));
            }
        }
        return ($finalC);
    }
588710
public function find($name) {
        $allCommands = array_keys($this->commands);

        $expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
            return preg_quote($matches[1]) . '[^:]*';
        }, $name);

        $commands = preg_grep('{^' . $expr . '}', $allCommands);

        if (empty($commands) || count(preg_grep('{^' . $expr . '$}', $commands)) < 1) {
            if (false !== $pos = strrpos($name, ':')) {
                $this->findNamespace(substr($name, 0, $pos));
            }

            $message = sprintf('Command "%s" is not defined.', $name);

            if ($alternatives = $this->findAlternatives($name, $allCommands)) {
                if (1 == count($alternatives)) {
                    $message .= "\n\nDid you mean this?\n    ";
                }
                else {
                    $message .= "\n\nDid you mean one of these?\n    ";
                }
                $message .= implode("\n    ", $alternatives);
            }

            throw new \InvalidArgumentException($message);
        }

        if (count($commands) > 1) {
            $commandList = $this->commands;

            $commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) {
                $commandName = $commandList[$nameOrAlias]->getName();

                return $commandName === $nameOrAlias || !in_array($commandName, $commands);
            });
        }

        $exact = in_array($name, $commands, true);
        if (count($commands) > 1 && !$exact) {
            $suggestions = $this->getAbbreviationSuggestions(array_values($commands));

            throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions));
        }

        return $this->get($exact ? $name : reset($commands));
    }
1113639
public function getCommandIfExists($string)
    {
        if (starts_with($string, $this->id)) {
            foreach ($this->commands as $commandName => $command) {
                if (starts_with($string, $this->id.$commandName)) {
                    return $command;
                }
            }
        }
    }
816668
public static function processSearchTerm(string $searchTerm): string
    {
        static $firstGroup = [
            '~[()&\\\:]+|^!+$|!+$|[&|*:]+!+|!+[&|*:]+$|(?:^|\s+)\*+~' => '',
            '~!\*|!+\s*~' => '!',
            '~"+\*+|"+~' => '"',
        ];
        $secondGroup = [
            '~([^!|&\s]*)"(.+)"([^!|&\s]*)~' => function (array $match): string {
                return trim(
                    $match[1] . ' (' . trim(preg_replace('~\s+~', '&', trim($match[2])), '&') . ') ' . $match[3]
                );
            },
        ];
        static $thirdGroup = [
            '~"|\(\s*\)~' => '',
            '~\s*\<([\-0-9]{1,1})\>\s*~' => '<\1>',
            '~([^*]+)\*+~' => '\1:*',
            '~[\s|]+~' => '|',
        ];

        $result = preg_replace(array_keys($firstGroup), $firstGroup, trim($searchTerm));
        $result = preg_replace_callback_array($secondGroup, $result);
        $result = trim(preg_replace(array_keys($thirdGroup), $thirdGroup, $result), '&|');

        return $result;
    }
188889
function getMatchingCommands(context, prefix) {
  var commands = cli.getMapping(context).requisition.system.commands;
  var reply = commands.getAll().filter(function(command) {
    if (command.hidden) {
      return false;
    }

    if (prefix && command.name.indexOf(prefix) !== 0) {
      // Filtered out because they don't match the search
      return false;
    }
    if (!prefix && command.name.indexOf(' ') != -1) {
      // We don't show sub commands with plain 'help'
      return false;
    }
    return true;
  });

  reply.sort(function(c1, c2) {
    return c1.name.localeCompare(c2.name);
  });

  reply = reply.map(function(command) {
    return command.toJson();
  });

  return reply;
}
1067661
private function _parseQueryString($queryString)
    {
        $queryObjs = json_decode($queryString);
        if (!$queryObjs) {
            throw new SqlException(
                'There was an error parsing your filter query string. '
                . 'The filter query must be in the format of a JSON object.'
            );
        }

        //inject a single object into an array.
        if (!is_array($queryObjs)) {
            $queryObj = $queryObjs;
            $queryObjs = [];
            $queryObjs[] = $queryObj;
        }

        $firstObj = true;
        foreach ($queryObjs as $queryObj) {
            $firstProperty = true;
            foreach ($queryObj as $property => $value) {
                if (is_array($value)) {
                    foreach ($value as $val) {
                        $this->_addFilterComparison($firstObj, $firstProperty, $property, $val);
                    }
                } else {
                    $this->_addFilterComparison($firstObj, $firstProperty, $property, $value);
                }
                $firstProperty = false;
            }
            $firstObj = false;
        }
    }
414735
private function getMatchStringParameterIndices($matchString, $pattern)
    {
        $indices = [];

        foreach ($pattern as $part) {
            if (!$this->isTokenPatternPart($part)) {
                $offset = 0;

                foreach ($indices as $currentIndex) {
                    $prefix = $currentIndex['prefix'];

                    if ($prefix == $part || substr_count($prefix, $part) || substr_count($part, $prefix)) {
                        $offset = $currentIndex['index'];
                    }
                }

                $indices[] = [
                    'prefix' => $part,
                    'index' => strpos($matchString, $part, $offset) + strlen($part)
                ];
            }
        }

        return $indices;
    }
939095
public function getResults($searchParams, $sort = false, $limit = false)
    {
        $searchParams = array_filter((array)$searchParams, array($this, 'clearEmptySearchFields'));

        // getQuery actually returns a DataList
        return $this->getQuery($searchParams, $sort, $limit);
    }
684071
public static function getMatches(string $branchString)
    {
        $branchString = trim($branchString);

        $regexList = [
            '/^\*?\ *?(\S+)\ +(\S{40})\ +(.+)$/',
            '/^\*?\ *?\(.*(detached).*\)\ +(\S{40})\ +(.+)$/',
        ];

        $matches = [];
        while (empty($matches) and $regex = array_pop($regexList)) {
            preg_match($regex, trim($branchString), $matches);
        }

        if (empty($matches)) {
            throw new \InvalidArgumentException(sprintf('the branch string is not valid: %s', $branchString));
        }

        return array_map('trim', $matches);
    }
1029261
public function selectByText($text, $exact_match = true)
	{
		$options = $this->getOptionsByText($text, $exact_match);

		if ( !$options ) {
			throw new SelectException('Cannot locate option with text: ' . $text, SelectException::TYPE_NOT_FOUND);
		}

		return $this->selectOptions($options, !$this->isMultiple());
	}
824981
public function runQuery($queryString){

		$cmd = strtoupper(substr(trim($queryString), 0, 6));
		static $list = array('UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1);
		$this->affectedRows = false;

		if(isset($list[$cmd])){
			$this->affectedRows = $this->resource->exec($queryString);

			if($this->affectedRows === false){
				$error = $this->resource->errorInfo();
				throw new DriverException("SQLSTATE[$error[0]]: $error[2]", $error[1], $queryString);
			} else
				return true;
		}

		$result = $this->resource->query($queryString);

		if($result === false){
			$error = $this->resource->errorInfo();
			throw new DriverException("SQLSTATE[$error[0]]: $error[2]", $error[1], $queryString);
		}else
			return $result;
	}
873153
public static function searchable($text, $wildcard = '*', $replacement = '%')
    {
        if (! static::contains($text, $wildcard)) {
            return [
                "{$text}",
                "{$text}{$replacement}",
                "{$replacement}{$text}",
                "{$replacement}{$text}{$replacement}",
            ];
        }

        return [str_replace($wildcard, $replacement, $text)];
    }
803526
public function highlightSearch($value, $searchString)
    {
        if (strlen($value) < 1 || strlen($searchString) < 1) {
            return $value;
        }
        preg_match_all("/$searchString+/i", $value, $matches);
        if (is_array($matches[0]) && count($matches[0]) > 0) {
            return str_replace($matches[0][0], '<em class="ccm-highlight-search">' . $matches[0][0] . '</em>', $value);
        }

        return $value;
    }