nqxcode/search-engine
Composer 安装命令:
composer require nqxcode/search-engine
包简介
Search engine for ORM based on Zend Lucene.
README 文档
README
Search engine gives opportunity of indexing of models (ActiveRecord) on demanded fields. Search engine uses the morphological filter for english and russian words. Morphological filter based on "phpMorphy" (morphological analyzer library).
In order that the model was available to indexation, it is necessary:
- Add name of class of model to list of model classes at initialization search engine.
- Declare model with
ISearchableinterface;
Usage
Initialization on search engine
$searchEngine = new SearchEngine\Engine('Product', $indexDirectory); // $indexDirectory path to index directory
Declare model with ISearchable interface
use SearchEngine\ISearchable; class Product implements ISearchable { // TODO ... }
Example of realization getAttributesForIndexing method of ISearchable interface
use SearchEngine\ISearchable; class Product implements ISearchable { // ... public funtion getAttributesForIndexing() { // list of couples "field name - field value" return array( new Attribute('fieldName', $this->fieldName), new Attribute('otherFieldName', $this->otherFieldName) ); } }
Operation on index
Full update for search index
$searchEngine->fullUpdateIndex();
Update index for ISearchable model
$searchEngine->updateIndex($model);
Delete index for ISearchable model
$searchEngine->deleteIndex($model);
Execute search query
/** * @var ZendSearch\Lucene\Search\QueryHit[] $hits */ $queryHits = $searchEngine->search($query);
Get result for paginator
/** * @var SearchEngine\Result\Hit[] $hits */ $hits = $searchEngine->parseHitsByRange($queryHits, $elementsPerPage, $currentPage); // get the found ISearchable model from each $hit foreach ($hits as $hit): $model = $hit->getItem(); }
Get full result
/** * @var SearchEngine\Result\Hit[] $hits */ $hits = $searchEngine->parseHits($queryHits); // get the found ISearchable model from each $hit foreach ($hits as $hit): $model = $hit->getItem(); }
License
Search engine licenced under the MIT license.
统计信息
- 总下载量: 79
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-10-15