/** * @param NodeInterface $node * @param string $term */ public function indexAction(NodeInterface $node, $term) { $request = array('suggests' => array('text' => $term, 'term' => array('field' => '_all'))); $response = $this->elasticSearchClient->getIndex()->request('GET', '/_suggest', array(), json_encode($request))->getTreatedContent(); $suggestions = array_map(function ($option) { return $option['text']; }, $response['suggests'][0]['options']); $this->view->assign('value', $suggestions); }
/** * Return the total number of hits for the query. * * @return integer * @api */ public function count() { $timeBefore = microtime(true); $request = $this->getRequest(); foreach ($this->unsupportedFieldsInCountRequest as $field) { if (isset($request[$field])) { unset($request[$field]); } } $response = $this->elasticSearchClient->getIndex()->request('GET', '/_count', [], json_encode($request)); $timeAfterwards = microtime(true); $treatedContent = $response->getTreatedContent(); $count = $treatedContent['count']; if ($this->logThisQuery === true) { $this->logger->log('Count Query Log (' . $this->logMessage . '): ' . json_encode($request) . ' -- execution time: ' . ($timeAfterwards - $timeBefore) * 1000 . ' ms -- Total Results: ' . $count, LOG_DEBUG); } return $count; }