yf_search_driver_manticore class

Manticore Search over SphinxQL: the sphinxsearch driver plus CREATE TABLE / DROP TABLE / TRUNCATE TABLE (RT mode, no index in the config), HIGHLIGHT() (text fields are stored by default) and max_matches raised for deep pages. Same connection settings: Manticore is a drop-in for SPHINX_HOST.

Fileplugins/search/classes/search/yf_search_driver_manticore.class.php
Use_class('search_driver_manticore', 'classes/search/')
Extendsyf_search_driver_sphinxsearch → yf_search_driver

Public properties

A site sets them in its config with $PROJECT_CONF['search_driver_manticore']['NAME'] = ...;

PropertyDefaultDescription
$FIELD_TYPES
array<string,string>
['text' => 'text', 'keyword' => 'string', 'string' => 'string', 'int' => 'bigint', 'uint' => 'uint', 'float' => 'float', ... (9 items)]
array (
  'text' => 'text',
  'keyword' => 'string',
  'string' => 'string',
  'int' => 'bigint',
  'uint' => 'uint',
  'float' => 'float',
  'bool' => 'bool',
  'timestamp' => 'timestamp',
  'json' => 'json',
)
create_index() schema type => Manticore column type

Inherited properties

from yf_search_driver_sphinxsearch: $BULK_SIZE, $CONNECT_TIMEOUT, $HOST, $PARENT, $RECONNECT_TRIES, $SPHINX, $SUGGEST_LIMIT

from yf_search_driver: $DEF_LIMIT, $MAX_LIMIT, $MAX_WINDOW, $MAX_WORDS, $last_error

Public methods 8

capabilities

public function capabilities()
    public function capabilities()
    {
        return array_replace(parent::capabilities(), ['ddl' => true]);
    }

create_index

public function create_index($index, $schema = [])

CREATE TABLE; 'suggest' => true adds min_infix_len = 2 (suggest() and infix search).

  • $schema mixed ['fields' => [name => text|keyword|string|int|uint|float|bool|timestamp|json], 'suggest' => bool]
    public function create_index($index, $schema = [])
    {
        $schema = (array) $schema;
        if ( ! $this->_is_valid_name($index)) {
            return $this->_fail('bad index');
        }
        $columns = [];
        foreach ((array) ($schema['fields'] ?? []) as $name => $type) {
            $sql_type = is_string($type) ? ($this->FIELD_TYPES[strtolower($type)] ?? null) : null;
            if ( ! $this->_is_valid_name($name) || $sql_type === null) {
                return $this->_fail('bad schema field ' . ($this->_is_valid_name($name) ? $name : 'name'));
            }
            if (strtolower($name) !== 'id') {
                $columns[] = $this->_quote_name($name) . ' ' . $sql_type;
            }
        }
        if ( ! $columns) {
            return $this->_fail('create_index() needs schema fields');
        }
        $sql = 'CREATE TABLE ' . $this->_quote_name($index) . ' (' . implode(', ', $columns) . ')';
        if ( ! empty($schema['suggest'])) {
            $sql .= " min_infix_len = '2'";
        }
        return $this->_write($sql);
    }

drop_index

public function drop_index($index)
    public function drop_index($index)
    {
        return $this->_is_valid_name($index) ? $this->_write('DROP TABLE IF EXISTS ' . $this->_quote_name($index)) : $this->_fail('bad index');
    }

truncate

public function truncate($index)
    public function truncate($index)
    {
        return $this->_is_valid_name($index) ? $this->_write('TRUNCATE TABLE ' . $this->_quote_name($index)) : $this->_fail('bad index');
    }

Methods starting with _ hooks and helpers; not routable as page actions

__call

public function __call($name, $args)

Catch missing method call.

    public function __call($name, $args)
    {
        return main()->extend_call($this, $name, $args);
    }
public function _highlight_sql($name, $pre, $post)
  • $name mixed validated field name
  • $pre mixed marker from _highlight_markers(), not HTML
    public function _highlight_sql($name, $pre, $post)
    {
        return "HIGHLIGHT({before_match='" . $this->_literal($pre) . "', after_match='" . $this->_literal($post) . "', limit=0}, '" . $this->_quote_name($name) . "')";
    }

_options

public function _options($p, $words)

Manticore refuses offset + limit above max_matches (default 1000); Sphinx 3.9 has no such cap (probed with 1200 documents, LIMIT 1050, 3). MAX_WINDOW bounds the value.

  • $p mixed normalized params

Returns string[]

    public function _options($p, $words)
    {
        $options = parent::_options($p, $words);
        $max = (int) $p['offset'] + (int) $p['limit'];
        if ($max > 1000) {
            $options[] = 'max_matches=' . $max;
        }
        return $options;
    }
public function _tables_column()
    public function _tables_column()
    {
        return 'Table';
    }

Inherited methods

from yf_search_driver: _doc_id(), _fail(), _highlight_html(), _highlight_markers(), _is_valid_name(), _name(), _normalize_filter(), _normalize_params(), _not_supported(), _without_id(), _words()

from yf_search_driver_sphinxsearch: _execute(), _filters_sql(), _init(), _literal(), _match_escape(), _quote_name(), _search_sql(), _transport(), _value(), _write(), add(), bulk(), connect(), delete(), escape(), index_exists(), is_ready(), raw(), search(), suggest(), update()