-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesHandler.php
More file actions
143 lines (128 loc) · 3.31 KB
/
esHandler.php
File metadata and controls
143 lines (128 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
require 'vendor/autoload.php';
class esCallHandler {
private $handler;
private $callindex,$calltype;
function __construct($hosts,$callid,$callindex) {
$this->handler = Elasticsearch\ClientBuilder::create()
->setHosts($hosts)
->build();
$this->callindex = $callid;
$this->calltype = $callindex;
}
function getViaUuid($uuid) {
$params = [
'index' => $this->callindex,
'type' => $this->calltype,
'id' => $uuid,
'client' => [ 'ignore' => 404 ]
];
try {
$response = $this->handler->get($params);
} catch (Exception $e) {
echo $e->getMessage(),"\n";
return NULL;
}
return $response;
}
function searchField($field,$data) {
$params = [
'index' => $this->callindex,
'type' => $this->calltype,
'body' => [
'query' => [
'match' => [
$field => $data
]
]
]
];
try {
$results = $this->handler->search($params);
return $results;
} catch (Exception $e) {
echo $e->getMessage(),"\n";
return NULL;
}
}
}
class esInsertStats {
private $totalCounted;
private $keyArray;
private $statAverage;
private $statCount;
private $statSum;
private $timesInserted;
function __construct() {
$this->statAverage = 0;
$this->statCount = 0;
$this->totalCounted = 0;
$this->keyArray = array();
$this->timesInserted = array();
$this->keyInsertedC = array();
}
function increment($key, $value = 1) {
$workingKey = &$this->keyArray[(string)$key];
$workingTI = &$this->timesInserted[(string)$key];
$insertCnt = &$this->keyInsertedC[(string)$key];
if(isset($workingKey)){
$workingKey += $value;
} else {
$workingKey = $value;
}
$this->totalCounted++;
if(isset($workingTI))
$workingTI = $workingTI + $value; // I donno :()
else
$workingTI = $value;
if(isset($insertCnt))
$insertCnt = $insertCnt + 1;
else
$insertCnt = 1;
//if
/*
//Take the Average, 42. Keycount = 27.
// To calculate new, add X to Average divide by Keycount
Average of what? Key has been inserted 5x times.
//$this->;
$this->statCount++;
*/
}
function getAverage($key) {
$workingKey = &$this->keyArray[(string)$key];
$workingTI = &$this->timesInserted[(string)$key];
$insertCnt = &$this->keyInsertedC[(string)$key];
var_dump($workingTI);
var_dump($workingKey);
if(isset($workingTI)){
return $workingTI / $workingKey;
} else {
return false;
}
}
//This just returns the damn array.
function getKeyList (){
$workingKey = &$this->keyArray;
return $workingKey;
}
function arrayDump(){
$workingKey = &$this->keyArray;
$output = "<br />\n";
foreach ($workingKey as $key => $keyval) {
$keyavg = $this->getAverage($key);
$output .= "For $key I got $keyval values averaging $keyavg<br />\n";
}
return $output;
}
//This should be commented out eventually.
function debugDUMP() {
var_dump($this->keyArray);
echo "\n<hr />\n";
var_dump($this->totalCounted);
echo "\n<hr />\n";
var_dump($this->timesInserted);
echo "\n<hr />\n";
var_dump($this->keyInsertedC);
}
}
?>