<?php /** * 问答ES模型 * Created by PhpStorm. * DateTime: 2019/7/18 11:48 */ namespace backend\models; use yii\elasticsearch\ActiveRecord; use yii\data\Pagination; use yii\helpers\ArrayHelper; use common\libs\CommonFunction; class QuestionEsModel extends ActiveRecord { /** * 数据库 * @date 2019-07-18 * @return null|object */ public static function getDb() { return \Yii::$app->get('elasticsearch'); } /** * 索引 * @date 2019-07-18 * @return string */ public static function index() { return 'insurance_question'; } /** * 类型 * @date 2019-07-18 * @return string */ public static function type() { return 'question'; } /** * 配置属性 * @date 2019-07-18 * @return array */ public function attributes() { $mapConfig = self::mapConfig(); return array_keys($mapConfig['properties']); } /** * 映射配置 * @date 2019-07-18 * @return array */ public static function mapConfig() { return [ 'properties' => [ 'question_id' => ['type' => 'integer'], //问题id 'hash_id' => ['type' => 'keyword'], //hash ID 'title' => ['type' => 'text', 'analyzer' => "ik_max_word"], //标题 'description' => ['type' => 'text', 'analyzer' => "ik_max_word"], //描述 'category_id' => ['type' => 'short'], //险种 'category_name' => ['type' => 'keyword'], //险种名称 'category_spell' => ['type' => 'keyword'], //险种拼音 'view_nums' => ['type' => 'integer'], //浏览次数 'status' => ['type' => 'short'], //状态 'reply_count' => ['type' => 'short'], //回复数 'created_at' => ['type' => 'integer'], //问题创建时间 'updated_at' => ['type' => 'integer'], //问题更新时间 'reply' => [ 'type' => 'nested',//嵌套文档 'properties' => [ 'reply_id' => ['type' => 'integer'], //回复ID 'content' => ['type' => 'text', 'analyzer' => "ik_max_word"], //回复内容 'manager_id' => ['type' => 'integer'], //经理人ID 'manager_name' => ['type' => 'keyword'], //经理人名称 'status' => ['type' => 'short'], //回复状态 'quality_grade' => ['type' => 'short'], //评级 'check_fail_reason' => ['type' => 'keyword'], //不通过原因 'word_count' => ['type' => 'integer'], //字数 'created_at' => ['type' => 'integer'], //创建
Yii2操作elasticsearch封装model
最新推荐文章于 2024-04-19 09:54:47 发布
这个博客介绍了如何在Yii2框架中封装Elasticsearch的model,包括设置数据库连接、索引、类型、属性映射,并提供了插入、更新、删除和查询数据的方法。
摘要由CSDN通过智能技术生成