PHP code example of tinymeng / yii2-solr
1. Go to this page and download the library: Download tinymeng/yii2-solr library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tinymeng / yii2-solr example snippets
'components' => [
'solr'=>[
'class'=> 'tinymeng\solr\Client',
'options' => [
'endpoint'=>[
[
'scheme' => 'http',
'host' => 'majiameng.com',
'port' => 8080,
'path' => '/solr/',
'core' => 'collection1',
],
[
'scheme' => 'http',
'host' => 'majiameng.com',
'port' => 8080,
'path' => '/solr/',
'core' => 'collection2',
],
],
]
],
]
namespace models\solr;
use \tinymeng\solr\ActiveRecord;
class Collection extends ActiveRecord
{
/** solr core name */
public static function tableName()
{
return 'collection1';
}
/** solr core attr */
public function attributes()
{
return [
'id',
'title',
'name',
];
}
}
$where = [
'id'=>1,
'type'=>28,
['between','type',1,100]
];
$select = ['id,title'];
$page = 1;
$page_size = 20;
$list = Collection::find()
->select($select)
->where($where)
->offset(($page-1)*$page_size)
->limit($page_size)
->orderBy('id asc,type asc')
->asArray()
->all();
$keywords = '汽车';
Collection::find()
->select($select)
->where(['keywords'=>$keywords])
->highlight([
"pre_tags"=>'<font color="#ff0000">',
"post_tags"=>'</font>',
"fields"=>['title','content']
])
->asArray()
->all();