wucdbm / sphinx-config-factory
Sphinx Config Factory
Installs: 2 886
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=8.2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.8
- wucdbm/php-cs-fixers: ~0.2
- dev-master
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.4.69
- v0.4.68
- v0.4.67
- v0.4.66
- v0.4.65
- v0.4.64
- v0.4.63
- v0.4.62
- v0.4.61
- v0.4.60
- v0.4.59
- v0.4.58
- v0.4.57
- v0.4.56
- v0.4.55
- v0.4.54
- v0.4.53
- v0.4.52
- v0.4.51
- v0.4.50
- v0.4.49
- v0.4.48
- v0.4.47
- v0.4.46
- v0.4.45
- v0.4.44
- v0.4.43
- v0.4.42
- v0.4.41
- v0.4.40
- v0.4.39
- v0.4.38
- v0.4.37
- v0.4.36
- v0.4.35
- v0.4.34
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
This package is auto-updated.
Last update: 2024-11-05 21:23:04 UTC
README
- Create a sphinx.conf.php file
- Create your index queries
bin/indexer --all /path/to/sphinx.conf.php
#!/usr/bin/php # # Sphinx configuration file sample # # WARNING! While this sample file mentions all available options, # it contains (very) short helper descriptions only. Please refer to # doc/sphinx.html for details. # <?php use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\ErrorHandler\Debug; use Wucdbm\Sphinx\ConfigFactory\EnvContainer; use Wucdbm\Sphinx\ConfigFactory\Factory; require dirname(__DIR__) . '/../vendor/autoload.php'; umask(0000); Debug::enable(); $dotEnv = new Dotenv(); $dotEnv->bootEnv(__DIR__ . '/path/to/main/env/file/.env'); $dotEnv->load(__DIR__ . '/path/to/sphinx/env/file/.env.local'); $env = new EnvContainer($_ENV); // Get ENV variables from your app // This allows you to have seamless deployments // While using your local environment/configurations on local setups $dsn = $env->get('DATABASE_URL'); $port = $env->get('SPHINX_PORT'); $mysqlPort = $env->get('SPHINX_MYSQL_PORT'); $ip = $env->get('SPHINX_HOST'); // Ensure those local env vars are present // This allows you to store sphinx data somewhere else on your local dev machine $env->ensure([ 'INDEX_STORAGE', 'LOG_PATH', 'QUERY_LOG_PATH', 'PID_PATH', ]); $indexStorage = $env->get('INDEX_STORAGE'); $logPath = $env->get('LOG_PATH'); $queryLogPath = $env->get('QUERY_LOG_PATH'); $pidPath = $env->get('PID_PATH'); $db = parse_url($dsn); $factory = new Factory([ 'sql_query_pre' => [ 'SET NAMES utf8', 'SET CHARACTER SET utf8', ], // Host vars are used in Factory::listen() templates (ES6 interpolation-like syntax) 'host_vars' => [ 'ip' => $ip, 'port' => $port, 'mysql_port' => $mysqlPort, ], ]); $dbConfig = [ 'type' => $db['scheme'], 'host' => $db['host'], 'port' => $db['port'], 'name' => ltrim($db['path'], '/'), 'user' => $db['user'], 'pass' => $db['pass'], ]; $baseIndexName = 'base_source'; echo $factory->configs([ // Create source to inherit from $factory->createBaseSource($baseIndexName, $dbConfig), // Create source, extend $baseIndexName $factory->createSource('main_index', $baseIndexName, [ # If you have extra columns in sphinx_index_meta, INSERT INTO is desirable over REPLACE INTO as that'll replace the whole record $factory->sqlQueryPre([ sprintf( ' INSERT INTO sphinx_index_meta (index_name, max_id, last_update) SELECT \'%s\', IFNULL(MAX(id), 0), UNIX_TIMESTAMP() FROM data_table ON DUPLICATE KEY UPDATE max_id = (SELECT IFNULL(MAX(id), 0) FROM data_table), last_update = UNIX_TIMESTAMP() ', 'main_index' ), ]), $factory->createAttrs([ 'field_id' => 'uint', 'boolean_attr' => 'bool', 'some_json' => 'json', 'another_field' => 'bigint', ]), $factory->sqlAttrMultiRangedQuery( 'uint', 'mva_attr', 'SELECT some_id AS id, mva_attr_id AS mva_attr FROM another_table at WHERE id >= $start AND id <= $end', 'SELECT MIN(id), MAX(id) FROM another_table' ), $factory->createSourceSql( 'SELECT id, some_attr FROM table', ), ]), // Optionally create delta source, extend the main one $factory->createSource('delta_index', 'main_index', [ $factory->sqlQueryPre([ sprintf( 'REPLACE INTO sphinx_index_meta (index_name, max_id, last_update) SELECT \'%s\', IFNULL(MAX(id), 0), UNIX_TIMESTAMP() FROM data_table', 'delta_index' ), ]), // possibly create range MVAs that fit the delta index with proper WHERE clauses $factory->createSourceSql( 'SELECT id, some_attr FROM table', [ 'another_field = \'some_val\'' ] ), ]), // Create index for main $factory->createIndex('main_index', 'main_index', $indexStorage), // Create delta index $factory->createIndex('delta_index', 'delta_index', $indexStorage), $factory->createDistributedIndex( 'distributed_index', [ [ 'ip' => $ip, 'port' => $port, 'name' => 'main_index', ], [ 'ip' => $ip, 'port' => $port, 'name' => 'delta_index', ], ] ), $factory->createIndexerConfig([ 'mem_limit' => '2047M', ]), $factory->createSearchdConfig([ 'listen' => [ $factory->listen('${ip}:${port}:sphinx'), $factory->listen('${ip}:${mysql_port}:mysql41'), ], 'log' => $logPath, 'query_log' => $queryLogPath, 'read_timeout' => '5', 'client_timeout' => '300', 'max_children' => '150', 'persistent_connections_limit' => '30', 'pid_file' => $pidPath, 'seamless_rotate' => '1', 'preopen_indexes' => '1', 'unlink_old' => '1', 'max_packet_size' => '32M', 'max_filters' => '256', 'max_filter_values' => '8192', 'max_batch_queries' => '32', 'workers' => 'threads', 'dist_threads' => '4', // disable binlog 'binlog_path' => '# disable logging', ]), $factory->createCommonConfig([]), $factory->eof() ]);