robotomize/fujes
最新稳定版本:0.4.0.0
Composer 安装命令:
composer require robotomize/fujes
包简介
Library for the fuzzy search to JSON document.
README 文档
README
Why?
Firstly, it is the implementation of the search on the format of the data in PHP. You can look up information on the fly. You can look for anything to JSON files. This is useful when your service accesses a different API.
The basis of the algorithm is taken Levenshtein.
Requirements
- php 5.6+
Installation
install composer (https://getcomposer.org/download/) composer require robotomize/fujes
or
git clone https://github.com/robotomize/fujes.git
Usage
Fast, minimal params, go
<?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;
Another example
Grep is used for highlighting
<?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;
With full options
<?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;
Documentation for Factory && Facade
Parameters
- path to json file '/go/to/path/name.json' or 'http://myapi/1.json'
- search line. 'search string'
- the depth of the array. (1-..) . Nesting output array. You will use a value of 1 or 2 the most.
- Display in json or PHP array. Output back to JSON?(true, false)
- Fetch one or more results. Get a set of results? Put true if you need to bring some results.
- Quality, 1 by default. @deprecated, but using. 1 default
- Version, master or dev. If you put the dev logs will be written about the exclusion or successful and not successful recognition. Once you see all the exceptions that fall.
Usage with example.php
Basic examples you can try that.
These examples work if you do
- git clone https://github.com/robotomize/fujes.git
- php -q src/example.php
<?php
php -q src/example.php
Fetch one entry
<?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} */
Next, fetch few entries.
<?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 */ }
Set up $multipleResult = trueand everything will be fine.
<?php $searchObject->setMultipleResult(true); /** * And this work */ print $searchObject->fetchFew(3) . PHP_EOL;
Factory
<?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;
Another factory example
<?php print SearchFactory::createSearchEngine( __DIR__ . '/data/biographical-directory-footnotes.json', 'linkoln', 1, true, true, 1, 'dev' )->fetchFew(6) . PHP_EOL;
License
Satis is licensed under the MIT License - see the LICENSE file for details
robotomize/fujes 适用场景与选型建议
robotomize/fujes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 206 次下载、GitHub Stars 达 17, 最近一次更新时间为 2015 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「json」 「search」 「find」 「fuzzy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 robotomize/fujes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 robotomize/fujes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 robotomize/fujes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package to retrieve data from Google Search Console
Kinikit - PHP Application development framework MVC component
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
ext-json wrapper with sane defaults
Abstraction Layer to index and search entities
A package to cast json fields, each sub-keys is castable
统计信息
- 总下载量: 206
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-15





