ltd-beget / sphinx-configurator
此包的最新版本(v2.0.0)没有可用的许可信息。
用于解析和编辑 sphinx.conf 文件的 PHP 库。
v2.0.0
2023-05-15 16:18 UTC
Requires
- php: >=7.2
- ltd-beget/sphinx-configuration-tokenizer: ^2.0.0
- marc-mabe/php-enum: >=2.2
- symfony/yaml: ^3.4.0 || ^4.0.0
Requires (Dev)
- phpunit/phpunit: ^8.5.3
- tideways/profiler: 2.0.*
This package is not auto-updated.
Last update: 2024-09-16 22:26:57 UTC
README
使用高级抽象以编程方式解析和编辑 sphinx.conf 文件的 PHP 库。
安装
composer require ltd-beget/sphinx-configurator
Sphinx 版本
该库支持以下版本的 Sphinx
- 2.2.10
- 2.2.8
- 2.2.6
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
用法
与文档提供者一起工作
此类提供有关具体选项的完整信息。如果您需要,可以单独使用它。
<?php require './vendor/autoload.php'; use LTDBeget\sphinx\enums\eSection; use LTDBeget\sphinx\enums\eVersion; use LTDBeget\sphinx\enums\options\eIndexerOption; use LTDBeget\sphinx\informer\Informer; // chose version $version = eVersion::V_2_2_10(); // get options help informer $informer = Informer::get($version); // chose section $section = eSection::INDEXER(); // check is known option type // useful only for version 2.1.9 and lower for section common $informer->isSectionExist($section); // see all options info foreach ($informer->iterateOptionInfo($section) as $optionInfo) { $optionInfo->getName(); $optionInfo->getDescription(); $optionInfo->getDocLink(); $optionInfo->getVersion(); $optionInfo->getSection(); $optionInfo->isIsMultiValue(); } // concrete option $option = eIndexerOption::LEMMATIZER_CACHE(); // is option exist in current version $informer->isKnownOption($section, $option); // is option permanently removed from newer version of Sphinx $informer->isRemovedOption($section, $option); // see concrete option info $optionInfo = $informer->getOptionInfo($section, $option); $optionInfo->getName(); $optionInfo->getDescription(); $optionInfo->getDocLink(); $optionInfo->getVersion(); $optionInfo->getSection(); $optionInfo->isIsMultiValue();
与配置对象一起工作
<?php require './vendor/autoload.php'; use LTDBeget\sphinx\configurator\Configuration; use LTDBeget\sphinx\enums\eVersion; use LTDBeget\sphinx\enums\options\eIndexOption; use LTDBeget\sphinx\enums\options\eSearchdOption; use LTDBeget\sphinx\enums\options\eSourceOption; // chose version $version = eVersion::V_2_2_10(); // get content of your configuration file $path_to_configuration = __DIR__. '/sphinx/conf/valid.example.conf'; $content = file_get_contents($path_to_configuration); // create object from string // if your configuration is valid it will be deserialized into the object // note that if your configuration has options which // was permanently removed from newer versions of sphinx // they will be ignored $configuration = Configuration::fromString($content, $version); // if you want, you can store the configuration in different formats $as_array = $configuration->toArray(); $as_json = $configuration->toJson(); // if you need to make sphinx conf file content cast object to string $as_plain = (string) $configuration; // configuration object serialized as array or json can be deserialized $configuration = Configuration::fromArray($as_array, $version); $configuration = Configuration::fromJson($as_json, $version); // or you can create empty object and fill it yourself $configuration = new Configuration($version); // adding source sections $source = $configuration->addSource('source1'); $source->addOption(eSourceOption::TYPE(), 'mysql'); $source = $configuration->addSource('source2', 'source1'); $source->addOption(eSourceOption::TYPE(), 'pgsql'); // is section has inheritance $source->isHasInheritance(); // get parent section object $source->getInheritance(); // note that sphinx has multi value options (MVA) // if you add twice or more times MVA option each time new option wil added $source->addOption(eSourceOption::XMLPIPE_ATTR_MULTI_64(), '1234567890'); $source->addOption(eSourceOption::XMLPIPE_ATTR_MULTI_64(), '0987654321'); // but if you add not MVA option twice, newer option erases older $source->addOption(eSourceOption::CSVPIPE_DELIMITER(), '|'); // will be erased $source->addOption(eSourceOption::CSVPIPE_DELIMITER(), '.'); // this is set in configuration // adding index sections $source = $configuration->addIndex('index1'); $source->addOption(eIndexOption::SOURCE(), 'source1'); $source = $configuration->addIndex('index2', 'index1'); $source->addOption(eIndexOption::SOURCE(), 'source2'); // check is has settings sections $configuration->isHasCommon(); $configuration->isHasSearchd(); $configuration->isHasIndexer(); // get settings section (it will be created if doesn't exists) $searchd = $configuration->getSearchd(); // add option to settings $searchd->addOption(eSearchdOption::LISTEN(), '9312'); // for indexer and common work is same $indexer = $configuration->getIndexer(); $common = $configuration->getCommon(); // each section can be deleted. // note, if you delete section that is parent to some one, its child will be removed too. $common->delete(); // iterating and manipulation with options // index and source is multiple sections // for iterating via it use iterateSource() or iterateIndex() foreach($configuration->iterateSource() as $section) { foreach ($section->iterateOptions() as $option) { $option->getInfo(); $option->getName(); $option->getValue(); if($option->getValue() === 'pgsql' && $option->getName()->is(eSourceOption::TYPE())) { $option->delete(); } if($option->getValue() === 'mysql' && $option->getName()->is(eSourceOption::TYPE())) { $option->setValue('pgsql'); } } } // searchd, indexer and common is single section // so iterate via options like this foreach($configuration->getIndexer()->iterateOptions() as $option) { $option->getInfo(); $option->getName(); $option->getValue(); } // and now, cast to string and see your brilliant configuration ;) echo $configuration;
Sphinx 配置标记仅
如果您只想标记 Sphinx 配置,则可以使用此 库
开发者
Docker
安装 Docker 和 docker-compose
转到 Docker
cd docker
构建镜像
docker-compose build
通过 Sphinx indextool 从 stubs 目录检查具体配置
docker-compose run --rm sphinx indextool --checkconfig -c /etc/sphinxsearch/valid.example.conf
重新生成文档
$ ./vendor/bin/phpdox
运行测试
$ php phpunit.phar --coverage-html coverage
许可
sphinx-configurator 在 MIT 许可下发布。有关详细信息,请参阅 包含的 LICENSE 文件。