<commit_before><?php

$currentVersion=OC_Appconfig::getValue('search_lucene', 'installed_version');
if (version_compare($currentVersion, '0.5.0', '<')) {
	//force reindexing of files
	$stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*lucene_status` WHERE 1=1');
	$stmt->execute();
	//clear old background jobs
	$stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*queuedtasks` WHERE `app`=?');
	$stmt->execute(array('search_lucene'));
}

if (version_compare($currentVersion, '0.5.2', '<')) {
	//delete duplicate entries and rescan them
	$stmt = OCP\DB::prepare('
		DELETE FROM `*PREFIX*lucene_status`
		WHERE `fileid` IN (
			SELECT `fileid`
			FROM `*PREFIX*lucene_status`
			GROUP BY `fileid`
			HAVING count(`status`) > 1
		)
	');
	$stmt->execute();
}<commit_msg>fix #1536 by adding another subselect to create a temp table<commit_after><?php

$currentVersion=OC_Appconfig::getValue('search_lucene', 'installed_version');
if (version_compare($currentVersion, '0.5.0', '<')) {
	//force reindexing of files
	$stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*lucene_status` WHERE 1=1');
	$stmt->execute();
	//clear old background jobs
	$stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*queuedtasks` WHERE `app`=?');
	$stmt->execute(array('search_lucene'));
}

if (version_compare($currentVersion, '0.5.2', '<')) {
	//delete duplicate id entries
	$stmt = OCP\DB::prepare('
		DELETE FROM `*PREFIX*lucene_status`
		WHERE `fileid` IN (
			SELECT `fileid`
			FROM (
				SELECT `fileid`
				FROM `*PREFIX*lucene_status`
				GROUP BY `fileid`
				HAVING count(`status`) > 1
			) AS `mysqlerr1093hack`
		)
	');
	$stmt->execute();
}
{'fraction_non_alphanumeric': 0.18017456359102244, 'fraction_numerical': 0.016209476309226933, 'mean_word_length': 5.245136186770428, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '1954808', 'n_tokens_mistral': 620, 'n_tokens_neox': 566, 'n_words': 125}