robotomize / fujes
该软件包已被废弃,不再维护。未建议替代软件包。
模糊搜索 JSON 文档的库。
0.4.0.0
2015-10-21 13:21 UTC
Requires
- php: >=5.6.0
- dflydev/markdown: ^1.0
- doctrine/instantiator: ^1.0
- erusev/parsedown: ^1.6
- monolog/monolog: ^1.17
- nesbot/carbon: ^1.20
- phpdocumentor/reflection-docblock: ^2.0
- sebastian/environment: ^1.3
- sebastian/exporter: ^1.2
- sebastian/global-state: ^1.1
- sebastian/recursion-context: ^1.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpspec/prophecy: ^1.5
- phpunit/php-code-coverage: ^3.0
- phpunit/php-invoker: ^1.1
- phpunit/php-text-template: ^1.2
- phpunit/php-timer: ^1.0
- phpunit/php-token-stream: ^1.4
- phpunit/phpunit: ^5.0
- phpunit/phpunit-mock-objects: ^3.0
- squizlabs/php_codesniffer: ^2.3
This package is not auto-updated.
Last update: 2020-08-25 22:47:12 UTC
README
为什么?
首先,这是在 PHP 数据格式上实现搜索的实现。您可以即时查找信息。您可以在 JSON 文件中查找任何内容。当您的服务访问不同的 API 时,这非常有用。
算法的基础是 Levenshtein。
要求
- php 5.6+
安装
install composer (https://getcomposer.org.cn/download/) composer require robotomize/fujes
或
git clone https://github.com/robotomize/fujes.git
用法
快速,最少参数,执行
<?php use robotomize\Fujes\SearchFactory; /** * * I want to find some planes */ print SearchFactory::find( 'http://api.travelpayouts.com/data/planes.json', 'Tu' )->fetchOne() . PHP_EOL; print SearchFactory::find( 'http://api.travelpayouts.com/data/planes.json', 'Boing 7' )->fetchOne() . PHP_EOL; print SearchFactory::find( 'http://api.travelpayouts.com/data/planes.json', 'An24' )->fetchOne() . PHP_EOL;
另一个示例
使用 Grep 进行高亮显示
<?php /** * I want to find some airports */ print SearchFactory::find( 'http://api.travelpayouts.com/data/airports.json ', 'Sheremetievo', 1, false )->fetchOne()['name'] . PHP_EOL; print SearchFactory::find( 'http://api.travelpayouts.com/data/airports.json ', 'Domogedov', 1, false )->fetchOne()['en'] . PHP_EOL; print SearchFactory::find( 'http://api.travelpayouts.com/data/airports.json ', 'Yugnosahalinsk', 1, false )->fetchOne()['en'] . PHP_EOL; print SearchFactory::find( 'http://api.travelpayouts.com/data/airports.json ', 'Puklovo', 1, false )->fetchOne()['en'] . PHP_EOL;
完整选项
<?php use robotomize\Fujes\SearchFacade; use robotomize\Fujes\SearchFactory; // With factory print SearchFactory::createSearchEngine( '/path/to/jsonurl', 'What are searching for string', 1, true, false, 1, 'master' )->fetchOne() . PHP_EOL; print SearchFactory::createSearchEngine( '/path/to/jsonurl', 'What are searching for string', 1, true, true, 1, 'master' )->fetchFew(3) . PHP_EOL;
Factory && Facade 文档
参数
- JSON 文件路径 '/go/to/path/name.json' 或 'http://myapi/1.json'
- 搜索行。'search string'
- 数组深度。 (1-..) . 嵌套输出数组。您最常使用 1 或 2。
- 以 JSON 或 PHP 数组显示。返回 JSON 吗?(true, false)
- 获取一个或多个结果。获取一组结果?需要一些结果吗?如果需要则设置为 true。
- 质量,默认为 1。@deprecated,但仍在使用。默认 1
- 版本,master 或 dev。如果您设置为 dev,则会记录有关排除或成功和未成功识别的日志。一旦您看到所有异常都会落下。
与 example.php 一起使用
您可以尝试的基本示例
如果您这样做,这些示例将有效
- git clone https://github.com/robotomize/fujes.git
- php -q src/example.php
<?php
php -q src/example.php
获取一个条目
<?php use robotomize\Fujes\SearchFacade; use robotomize\Fujes\SearchFactory; /** * Helper options. Search into biographical-directory-footnotes.json. * Match string Christensen * Output encode to json */ $options = [ 'json_file_name' => __DIR__ . '/data/biographical-directory-footnotes.json', 'search_string' => 'Christensen', 'depth_into_array' => '1', 'output_json' => true, 'multiple_result' => false, 'search_quality' => 1, 'version' => 'dev' ]; $searchObject = new SearchFacade( $options['json_file_name'], $options['search_string'], $options['depth_into_array'], $options['output_json'], $options['multiple_result'], $options['search_quality'], $options['version'] ); print $searchObject->fetchOne(); /** * Output this * * {"item":"Donna Christian-Green, St. Croix ","note":"[5125: * Biographical information under Donna Marie Christian Christensen. ]", * "line":56939} */
接下来,获取一些条目。
<?php /** * Get exception */ try { print $searchObject->fetchFew(3) . PHP_EOL; } catch (\Exception $ex) { print $ex->getMessage() . PHP_EOL; /** * Output this exception * multipleResult flag off, use $this->setMultipleResult(true) * and call this function again */ }
设置 $multipleResult = true,一切都会顺利。
<?php $searchObject->setMultipleResult(true); /** * And this work */ print $searchObject->fetchFew(3) . PHP_EOL;
工厂
<?php /** * The following example, you can use the factory. */ print SearchFactory::createSearchEngine( __DIR__ . '/../src/data/cities.json', 'vladvostk', 2, false, false, 1, 'dev' )->fetchOne()['name'] . PHP_EOL; print SearchFactory::createSearchEngine( __DIR__ . '/../src/data/cities.json', 'Mosco', 1, true, false, 1, 'dev' )->fetchOne() . PHP_EOL;
另一个工厂示例
<?php print SearchFactory::createSearchEngine( __DIR__ . '/data/biographical-directory-footnotes.json', 'linkoln', 1, true, true, 1, 'dev' )->fetchFew(6) . PHP_EOL;
许可证
Satis 在 MIT 许可证下授权 - 详细信息请参阅 LICENSE 文件