Skip to content

Commit

Permalink
Message delivery status support for ElasticSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Jul 10, 2023
1 parent b8a19e5 commit 043e16d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion classes/erlhcoreclassmodelesmsg.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public function getState()
'name_support' => $this->name_support,
'dep_id' => $this->dep_id,
'gbot_id' => $this->gbot_id,
'status_sub' => $this->status_sub
'status_sub' => $this->status_sub,
'del_st' => $this->del_st
);

return $states;
Expand Down Expand Up @@ -48,6 +49,7 @@ public function __get($var)
public $user_id = null;

public $dep_id = null;
public $del_st = null;

public $op_user_id = null;

Expand Down
1 change: 1 addition & 0 deletions classes/lhelasticsearchindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ public static function indexMessages($params)
$esMsg->time = $item->time * 1000;
$esMsg->name_support = $item->name_support;
$esMsg->user_id = $item->user_id;
$esMsg->del_st = $item->del_st;
$esMsg->dep_id = (int)$infoChat[$item->chat_id]['dep_id'];
$esMsg->op_user_id = (int)$infoChat[$item->chat_id]['user_id'];
$esMsg->gbot_id = (int)$infoChat[$item->chat_id]['gbot_id'];
Expand Down
23 changes: 23 additions & 0 deletions classes/lhelasticsearchstatistic.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,14 @@ public static function statisticGetnumberofchatspermonth($params, $aggr = 'month
$sparams['body']['aggs']['chats_over_time']['aggs']['msg_system']['filter']['term']['user_id'] = -1;
$sparams['body']['aggs']['chats_over_time']['aggs']['msg_bot']['filter']['term']['user_id'] = -2;

// Bot messages delivery status
$sparams['body']['aggs']['chats_over_time']['aggs']['msg_del_bot']['filter']['term']['user_id'] = -2;
$sparams['body']['aggs']['chats_over_time']['aggs']['msg_del_bot']['aggs']['msg_del_status']['terms']['field'] = 'del_st';

// Operator messages delivery status
$sparams['body']['aggs']['chats_over_time']['aggs']['msg_del_op']['filter']['range']['user_id']['gt'] = 0;
$sparams['body']['aggs']['chats_over_time']['aggs']['msg_del_op']['aggs']['msg_del_status']['terms']['field'] = 'del_st';

$paramsOrigIndex = $paramsOrig = $params;

if ($aggr == 'month') {
Expand Down Expand Up @@ -1003,6 +1011,21 @@ public static function statisticGetnumberofchatspermonth($params, $aggr = 'month
$numberOfChats[$keyDateUnix]['msg_user'] = $bucket['msg_user']['doc_count'];
$numberOfChats[$keyDateUnix]['msg_system'] = $bucket['msg_system']['doc_count'];
$numberOfChats[$keyDateUnix]['msg_bot'] = $bucket['msg_bot']['doc_count'];

$numberOfChats[$keyDateUnix]['msgdelbot'] = [];
$numberOfChats[$keyDateUnix]['msgdelop'] = [];

if (isset($bucket['msg_del_op']['msg_del_status']['buckets'])) {
foreach ($bucket['msg_del_op']['msg_del_status']['buckets'] as $buckedDelivery) {
$numberOfChats[$keyDateUnix]['msgdelop'][$buckedDelivery['key']] = $buckedDelivery['doc_count'];
}
}

if (isset($bucket['msg_del_bot']['msg_del_status']['buckets'])) {
foreach ($bucket['msg_del_bot']['msg_del_status']['buckets'] as $buckedDelivery) {
$numberOfChats[$keyDateUnix]['msgdelbot'][$buckedDelivery['key']] = $buckedDelivery['doc_count'];
}
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions doc/structure_elastic.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@
"status_sub": {
"type": "integer"
},
"del_st": {
"type": "short"
},
"name_support": {
"type": "text"
}
Expand Down

0 comments on commit 043e16d

Please sign in to comment.