php sorl扩展查询报错,yii2使用solr扩展

yii2使用solr扩展

Installcomposer require tinymeng/yii2-solr dev-master类库使用的命名空间为\\tinymeng\\solr

注意不必安装PHP的Solr扩展(由于solr扩展很久没有更新过了,仅支持PHP5.6左右的版本,PHP7.0以上版本安装不上)

暂时只实现了AR查询的使用

未实现AR的增删改,可以使用 yii::$app->solr 进行操作

引用小部件 main.php'components' => [

'solr'=>[

'class'=> 'tinymeng\solr\Client',

'options' => [

'endpoint'=>[

[

'scheme' => 'http',

'host' => '127.0.0.1',

'port' => 8080,

'path' => '/solr/',

'core' => 'collection1',

],

[

'scheme' => 'http',

'host' => '127.0.0.1',

'port' => 8080,

'path' => '/solr/',

'core' => 'collection2',

],

],

]

],

]

yii AR 查询模式

create Model<?php

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"=>'',

"post_tags"=>'',

"fields"=>['title','content']

])

->asArray()

->all();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值