naroga / search-bundle
一个无差别的搜索包。
dev-master
2016-02-11 10:39 UTC
Requires
- guzzlehttp/guzzle: ~6.0
- jms/serializer-bundle: ~1.0
Requires (Dev)
- phpunit/phpunit: 5.0.*
This package is auto-updated.
Last update: 2024-09-11 23:38:53 UTC
README
Naroga的搜索包
这是一个搜索包,专为DistantJobHire独家开发。
要求
此项目使用了一些酷炫的PHP 7.0特性(如Null Coalesce操作符,Spaceship操作符,标量类型提示,函数返回类型提示等)。它还使用了Symfony3,这意味着它共享其要求。另外,您还需要安装php-curl
扩展。
安装
要安装此包,请使用composer要求
$ composer require naroga/search-bundle dev-master
使用
索引文档
$ php bin/console search:add <filename>
File written successfully with ID <ID>
这将索引文件内容。
删除文档
$ php bin/console search:delete <id>
<#> entries deleted successfully.
这将删除一个索引文档。
搜索文档
$php bin/console search:search <expression>
Found <#> results:
...
这将根据提供的表达式搜索包含匹配项的文档。
单元测试
克隆此仓库,使用composer install
安装依赖项,并运行phpunit
。
切换搜索引擎
要切换到另一个搜索引擎(以MyCustomSearchEngine为例),您必须创建一个新的包。
$ php bin/console generate:bundle
现在,将此包定义为NarogaSearchBundle的父包
#MyCustomSearchBundle.php
class MyCustomSearchBundle extends Bundle
{
public function getParent()
{
return 'NarogaSearchBundle';
}
}
现在,创建一个新的MyCustomSearchEngine
类,该类实现了EngineInterface
class MyCustomSearchEngine implements EngineInterface
{
public function add(string $name, string $content)
{
// TODO: Implement add() method.
}
public function search(string $expression) : array
{
// TODO: Implement search() method.
}
public function delete(string $id)
{
// TODO: Implement delete() method.
}
}
在services.yml文件中,将搜索引擎定义为服务
services:
mycustomengine.engine:
class: My\Class\Path
arguments: [ "here_come_your_dependencies" ]
仍在services
部分,覆盖naroga.search
服务
naroga.search:
class: Naroga\SearchBundle\Search\Search
arguments: [ "@mycustomengine.engine" ] #pass your custom service here as a parameter.
现在您可以开始了!
许可证
此项目是专有的,因此未经所有者(DistantJobHire)的明确书面同意,不得使用、复制、修改或分发。