yii\sphinx\QueryBuilder::callSnippets PHP Метод

callSnippets() публичный Метод

Builds a SQL statement for call snippet from provided data and query, using specified index settings.
public callSnippets ( string $index, string | array $source, string $match, array $options, array &$params ) : string
$index string name of the index, from which to take the text processing settings.
$source string | array is the source data to extract a snippet from. It could be either a single string or array of strings.
$match string the full-text query to build snippets for.
$options array list of options in format: optionName => optionValue
$params array the binding parameters that will be modified by this method so that they can be bound to the Sphinx command later.
Результат string the SQL statement for call snippets.
    public function callSnippets($index, $source, $match, $options, &$params)
    {
        if (is_array($source)) {
            $dataSqlParts = [];
            foreach ($source as $sourceRow) {
                $phName = self::PARAM_PREFIX . count($params);
                $params[$phName] = $sourceRow;
                $dataSqlParts[] = $phName;
            }
            $dataSql = '(' . implode(',', $dataSqlParts) . ')';
        } else {
            $phName = self::PARAM_PREFIX . count($params);
            $params[$phName] = $source;
            $dataSql = $phName;
        }
        $indexParamName = self::PARAM_PREFIX . count($params);
        $params[$indexParamName] = $index;
        $matchSql = $this->buildMatch($match, $params);
        if (!empty($options)) {
            $optionParts = [];
            foreach ($options as $name => $value) {
                if ($value instanceof Expression) {
                    $actualValue = $value->expression;
                } else {
                    $actualValue = self::PARAM_PREFIX . count($params);
                    $params[$actualValue] = $value;
                }
                $optionParts[] = $actualValue . ' AS ' . $name;
            }
            $optionSql = ', ' . implode(', ', $optionParts);
        } else {
            $optionSql = '';
        }
        return 'CALL SNIPPETS(' . $dataSql . ', ' . $indexParamName . ', ' . $matchSql . $optionSql . ')';
    }