markusos / simple-search
PHP简单搜索引擎
dev-master
2017-03-29 17:58 UTC
Requires
- php: >=5.4.0
- camspiers/porter-stemmer: 1.0.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: 4.4.*
This package is not auto-updated.
Last update: 2024-09-24 03:59:38 UTC
README
PHP简单搜索引擎
- 使用多词查询查询文档索引。
- 搜索结果使用TF-IDF词权重和余弦相似度进行排序。
- 使用MongoDB、MySQL或SQLite存储文档。
- 将搜索索引存储在Memcached或MongoDB中。
- 易于扩展以支持其他存储提供者。
- 使用Snowball或Porter词干提取。
注意:此项目仍在开发中
安装
$ composer require markusos/simple-search dev-master
在运行搜索引擎时,请确保MongoDB和Memcached进程在服务器上运行。
系统要求
您需要PHP >= 5.4.0来使用markusos\simple-search
,但推荐使用最新的稳定版本PHP。
如果您想使用MongoDB存储和/或索引提供者,您需要安装mongo
扩展。
$ pecl install mongo
要使用snowball词干提取器,您还需要安装stem
扩展。
$ pecl install stem
确保在安装stem
扩展时安装您需要的语言。
用法
基本用法
索引文档
<?php $document = new Search\Document( 'Test Title', 'This is a test document with some content to be searchable.' ); $engine = new Search\Engine(); $engine->addDocument($document);
搜索
<?php $engine = new Search\Engine(); $result = $engine->search('test document');
自定义配置
搜索引擎支持通过可交换的服务提供者进行自定义。在初始化搜索引擎时,可以替换默认实现并提供自己的实现。
<?php $config = Search\Config\Config::createBuilder() ->tokenizer($tokenizer) ->store($store) ->index($index) ->ranker($ranker) ->stopWords($stopWords) ->build(); $engine = new Search\Engine($config);
或者,您可以使用默认设置并覆盖您需要的设置
<?php $config = Search\Config\Config::createBuilder() ->defaultConfig() ->stopWords(['new', 'list', 'of', 'stop', 'words']) ->build(); $engine = new Search\Engine($config);
测试
Simple Search有一个PHPUnit测试套件。要从项目目录中运行测试,请运行以下命令
$ phpunit
如果您不想运行需要Memcached和MongoDB启动的集成测试,只需运行
$ phpunit --testsuite unit
许可证
MIT许可证 (MIT)
版权所有 (c) 2015 Markus Östberg