<commit_before><?php

class CM_Search_Index_Cli extends CM_Cli_Runnable_Abstract {

	/**
	 * @param string|null  $indexName Index name, if not provided all application indexes will be created.
	 */
	public function create($indexName = null) {
		if ($indexName) {
			$indexes = array($this->_getIndex($indexName));
		} else {
			$indexes = $this->_getIndexes();
		}
		foreach ($indexes as $index) {
			$this->_echo('Creating search index `' . $index->getIndex()->getName() . '`...');
			$index->createVersioned();
		}
	}

	/**
	 * @param string|null $indexName Index name, if not provided all indexes will be updated.
	 * @param string|null $host      Elastic search server host.
	 * @param int|null    $port      Elastic search server port.
	 * @throws CM_Exception_Invalid
	 */
	public function update($indexName = null, $host = null, $port = null) {
		if ($indexName) {
			$indexes = array($this->_getIndex($indexName, $host, $port));
		} else {
			$indexes = $this->_getIndexes($host, $port);
		}
		foreach ($indexes as $index) {
			$indexName = $index->getIndex()->getName();
			$key = 'Search.Updates_' . $index->getType()->getName();
			try {
				$ids = CM_Cache_Redis::sFlush($key);
				$ids = array_filter(array_unique($ids));
				$index->update($ids);
			} catch (Exception $e) {
				$message = $indexName . '-updates failed. 	';
				if (isset($ids)) {
					$message .= 'Re-adding ' . count($ids) . ' ids to queue.' . PHP_EOL;
					foreach ($ids as $id) {
						CM_Cache_Redis::sAdd($key, $id);
					}
				}
				$message .= 'Reason: ' . $e->getMessage();
				throw new CM_Exception_Invalid($message);
			}
		}
	}<commit_msg>t1739: Added index refresh to CLI<commit_after><?php

class CM_Search_Index_Cli extends CM_Cli_Runnable_Abstract {

	/**
	 * @param string|null  $indexName Index name, if not provided all application indexes will be created.
	 */
	public function create($indexName = null) {
		if ($indexName) {
			$indexes = array($this->_getIndex($indexName));
		} else {
			$indexes = $this->_getIndexes();
		}
		foreach ($indexes as $index) {
			$this->_echo('Creating search index `' . $index->getIndex()->getName() . '`...');
			$index->createVersioned();
			$index->getIndex()->refresh();
		}
	}

	/**
	 * @param string|null $indexName Index name, if not provided all indexes will be updated.
	 * @param string|null $host      Elastic search server host.
	 * @param int|null    $port      Elastic search server port.
	 * @throws CM_Exception_Invalid
	 */
	public function update($indexName = null, $host = null, $port = null) {
		if ($indexName) {
			$indexes = array($this->_getIndex($indexName, $host, $port));
		} else {
			$indexes = $this->_getIndexes($host, $port);
		}
		foreach ($indexes as $index) {
			$indexName = $index->getIndex()->getName();
			$key = 'Search.Updates_' . $index->getType()->getName();
			try {
				$ids = CM_Cache_Redis::sFlush($key);
				$ids = array_filter(array_unique($ids));
				$index->update($ids);
				$index->getIndex()->refresh();
			} catch (Exception $e) {
				$message = $indexName . '-updates failed. 	';
				if (isset($ids)) {
					$message .= 'Re-adding ' . count($ids) . ' ids to queue.' . PHP_EOL;
					foreach ($ids as $id) {
						CM_Cache_Redis::sAdd($key, $id);
					}
				}
				$message .= 'Reason: ' . $e->getMessage();
				throw new CM_Exception_Invalid($message);
			}
		}
	}
{'fraction_non_alphanumeric': 0.17436661698956782, 'fraction_numerical': 0.0011922503725782414, 'mean_word_length': 3.364109232769831, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6936506', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1107, 'n_words': 265}