sammaye/yii2-solr
Composer 安装命令:
composer require sammaye/yii2-solr
包简介
Solr plugin for the Yii2 framework built ontop of Solarium
README 文档
README
A Yii2 Solr Extension built on top of Solarium.
Essentially this is a Yii2 plugin for Solarium and it is dirt simple to use, all it does is abstract certain parts of Solarium into Yii2.
There are only two files you need to pay attention to in this repository:
- Client - The Solr client, representing the connection
- SolrDataProvider - The data provider you can use with all your widgets etc.
Normal querying of Solr is very simple with this extension and I will in fact point you towards the Solarium Documentation.
The only part Yii2 really has is in providing the Solarium client class as a application component, to show an example:
$query = Yii::$app->solr->createSelect(); $query->setQuery('edismax&qf=title^20.0 OR description^0.3'); $result = Yii::$app->solr->select($query); var_dump($result->getNumFound());
That is what it takes to query Solarium. As you notice the only part of the Solarium documentation you need to replace is where they use $client and instead you
should use Yii::$app->solr (or whatever you have called the Solr application component in your configuration).
To setup the application you merely add it to your configuration. As an example:
'solr' => [ 'class' => 'sammaye\solr\Client', 'options' => [ 'endpoint' => [ 'solr1' => [ 'host' => '10.208.225.66', 'port' => '8983', 'path' => '/', 'collection' => 'myColl ] ] ] ],
The options part of the configuration is a one-to-one match to Solariums own constructor and options.
Using the data provider for widgets is just as easy, as another example:
$query = Yii::$app->solr->createSelect(); $query->setQuery('(alt_subject_mpath:' . $model->path . ' OR alt_subject_mpath:' . $model->path . '.*) AND live:1'); new SolrDataProvider([ 'query' => $query, // an example class which assigns variables to the model(s) // and returns the model(s) 'modelClass' => 'SolrResult', 'sort' => [ 'attributes' => [ 'title', 'sales', 'score' ] ] ]);
As you will notice the Solarium query object can go straight into the data providers query property. Just like in Yii1 you need to provide a modelClass since this extension is not
connected to active record directly.
The reasoning for not implementing a QueryInterface and making the query hook into an active record is because in many cases the Solr index represents many active records all at once
as such I wanted to make it free form and give the user the ability to produce a specific Solr model that can return any active record they see fit while the data provider just feeds the
multiple classes into a widget.
So now the basics are understood, you will see there are two others files:
- Solr - A helper that I used in my application and I just added in case it would be useful to others
- SolrDocumentInterface - An interface that defines a single function to be used within Solr models
The Solr class is just a helper that you don't really need if you don't want it so I will move onto the SolrDocumentInterface. The interface class just defines a single function
populateFromSolr which takes one argument: the Solarium document object (from a loop). It returns a single Yii2 model. The populateFromSolr function is called every
iteration of the data providers prepareModels() function and only ever takes a single document.
sammaye/yii2-solr 适用场景与选型建议
sammaye/yii2-solr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 63.28k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2014 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「solr」 「solarium」 「extension」 「yii2」 「yii2-extension」 「sammaye」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sammaye/yii2-solr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sammaye/yii2-solr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sammaye/yii2-solr 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A bundle which extend ibexa solr search handler
This extension provides integration with solr to output content from TYPO3 in JSON format.
A custom URL rule class for Yii 2 which allows to create translated URL rules
Laminas Module for interaction between a laminas application and a SOLR search engine using Solarium
An Apache Solr driver for laravel scout
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
统计信息
- 总下载量: 63.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-04-30