public function search($string, $lang = 'cs') { $index = $this->client->getIndex($lang . '_screenplay'); $result = $index->search($string); $results = $result->getResults(); return $results; }
/** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { ini_set('memory_limit', '4G'); $lang = $input->getArgument(self::LANGUAGE_ARGUMENT); /** @var Language $language */ if (($language = $this->languagesRepository->findOneBy(['shortCode' => $lang])) === NULL) { $output->writeln("<error>Unknown language {$lang} given!"); return 1; } $index = $this->elastic->getIndex('dwarf'); $type = $index->getType($language->getShortCode() . '_screenplay'); /** @var Season[] $seasons */ $seasons = $this->seasonsRepository->findBy(['language' => $language]); foreach ($seasons as $season) { $output->writeln("Importing season {$season->getNumber()}..."); foreach ($season->getEpisodes() as $episode) { foreach ($episode->getScenarios() as $screenplay) { if ($screenplay->getCharacter() !== NULL) { $document = new Document($screenplay->getId(), ['text' => $screenplay->getText(), 'episode' => ['id' => $episode->getId(), 'number' => $episode->getNumber(), 'name' => $episode->getName(), 'slug' => $episode->getSlug()], 'season' => ['id' => $season->getId(), 'number' => $season->getNumber()], 'character' => ['name' => $screenplay->getCharacter()->getName(), 'slug' => $screenplay->getCharacter()->getSLug()], 'line' => $screenplay->getLine()], $type, $index); $type->addDocument($document); } } } } }
/** * @return string */ public function getPanel() { if (!$this->queries) { return NULL; } ob_start(); $esc = callback('Nette\\Templating\\Helpers::escapeHtml'); $click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = FALSE, $d = 4) { return \Tracy\Dumper::toHtml($o, array('collapse' => $c, 'depth' => $d)); } : callback('\\Tracy\\Helpers::clickableDump'); $totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none'; $extractData = function ($object) { if ($object instanceof Elastica\Request) { $data = $object->getData(); } elseif ($object instanceof Elastica\Response) { $data = $object->getData(); } else { return array(); } try { return !is_array($data) ? Json::decode($data, Json::FORCE_ARRAY) : $data; } catch (Nette\Utils\JsonException $e) { try { return array_map(function ($row) { return Json::decode($row, Json::FORCE_ARRAY); }, explode("\n", trim($data))); } catch (Nette\Utils\JsonException $e) { return $data; } } }; $processedQueries = array(); $allQueries = $this->queries; foreach ($allQueries as $authority => $requests) { /** @var Elastica\Request[] $item */ foreach ($requests as $i => $item) { $processedQueries[$authority][$i] = $item; if (isset($item[3])) { continue; // exception, do not re-execute } if (stripos($item[0]->getPath(), '_search') === FALSE || $item[0]->getMethod() !== 'GET') { continue; // explain only search queries } if (!is_array($data = $extractData($item[0]))) { continue; } try { $response = $this->client->request($item[0]->getPath(), $item[0]->getMethod(), $item[0]->getData(), array('explain' => 1) + $item[0]->getQuery()); // replace the search response with the explained response $processedQueries[$authority][$i][1] = $response; } catch (\Exception $e) { // ignore } } } require __DIR__ . '/panel.phtml'; return ob_get_clean(); }
/** * @return Index */ private function getIndex() { return $this->client->getIndex(self::ELASTIC_INDEX); }
/** * @param string $indexName * @return ElasticIndex */ private function getIndex($indexName) { return $this->client->getIndex($indexName); }