1 | <?php |
||
25 | class Client extends BaseClient |
||
26 | { |
||
27 | /** |
||
28 | * Stores created indexes to avoid recreation. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | private $indexCache = []; |
||
33 | |||
34 | /** |
||
35 | * Symfony's debugging Stopwatch. |
||
36 | * |
||
37 | * @var Stopwatch|null |
||
38 | */ |
||
39 | private $stopwatch; |
||
40 | |||
41 | /** |
||
42 | * @param string $path |
||
43 | * @param string $method |
||
44 | * @param array $data |
||
45 | * @param array $query |
||
46 | * |
||
47 | * @return \Elastica\Response |
||
48 | */ |
||
49 | 10 | public function request($path, $method = Request::GET, $data = [], array $query = []) |
|
50 | { |
||
51 | 10 | if ($this->stopwatch) { |
|
52 | 9 | $this->stopwatch->start('es_request', 'fos_elastica'); |
|
53 | 9 | } |
|
54 | |||
55 | 10 | $response = parent::request($path, $method, $data, $query); |
|
56 | 10 | $responseData = $response->getData(); |
|
57 | |||
58 | 10 | if (isset($responseData['took']) && isset($responseData['hits'])) { |
|
59 | 2 | $this->logQuery($path, $method, $data, $query, $response->getQueryTime(), $response->getEngineTime(), $responseData['hits']['total']); |
|
60 | 2 | } else { |
|
61 | 9 | $this->logQuery($path, $method, $data, $query, $response->getQueryTime(), 0, 0); |
|
62 | } |
||
63 | |||
64 | 10 | if ($this->stopwatch) { |
|
65 | 9 | $this->stopwatch->stop('es_request'); |
|
66 | 9 | } |
|
67 | |||
68 | 10 | return $response; |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param string $name |
||
73 | * |
||
74 | * @return Index|mixed |
||
75 | */ |
||
76 | 12 | public function getIndex($name) |
|
84 | |||
85 | /** |
||
86 | * Sets a stopwatch instance for debugging purposes. |
||
87 | * |
||
88 | * @param Stopwatch $stopwatch |
||
89 | */ |
||
90 | 13 | public function setStopwatch(Stopwatch $stopwatch = null) |
|
94 | |||
95 | /** |
||
96 | * Log the query if we have an instance of ElasticaLogger. |
||
97 | * |
||
98 | * @param string $path |
||
99 | * @param string $method |
||
100 | * @param array $data |
||
101 | * @param array $query |
||
102 | * @param int $queryTime |
||
103 | * @param int $engineMS |
||
104 | * @param int $itemCount |
||
105 | */ |
||
106 | 10 | private function logQuery($path, $method, $data, array $query, $queryTime, $engineMS = 0, $itemCount = 0) |
|
125 | } |
||
126 |