<commit_before><?php

if (!defined('SMF'))
	die('No direct access...');

function integrate_character_autosuggest(&$searchTypes)
{
	$searchTypes['memberchar'] = 'MemberChar';
	$searchTypes['character'] = 'Character';
	$searchTypes['rawcharacter'] = 'RawCharacter';
}

function AutoSuggest_Search_Character()
{
	global $user_info, $smcFunc, $context;

	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search'])) . '*';
	$_REQUEST['search'] = strtr($_REQUEST['search'], ['%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;']);

	$xml_data = [
		'items' => [
			'identifier' => 'item',
			'children' => [],
		],
	];

	// Find the characters
	$request = $smcFunc['db_query']('', '
		SELECT chars.id_character, chars.id_member, chars.character_name, mem.real_name
		FROM {db_prefix}characters AS chars
		INNER JOIN {db_prefix}members AS mem ON (chars.id_member = mem.id_member)
		WHERE {raw:real_name} LIKE {string:search}
			AND mem.is_activated IN (1, 11)
		LIMIT ' . ($smcFunc['strlen']($_REQUEST['search']) <= 2 ? '100' : '800'),
		[
			'real_name' => $smcFunc['db_case_sensitive'] ? 'LOWER(character_name)' : 'character_name',
			'search' => $_REQUEST['search'],
		]
	);
	while ($row = $smcFunc['db_fetch_assoc']($request))
	{
		$row['display_name'] = strtr($row['character_name'] . ' (' . $row['real_name'] . ')', ['&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;']);

		$xml_data['items']['children'][$row['id_member']] = [
			'attributes' => [
				'id' => $row['id_member'] . ';area=characters;char=' . $row['id_character'],
			],
			'value' => $row['display_name'],
		];
	}
	$smcFunc['db_free_result']($request);

	return $xml_data;
}

function AutoSuggest_Search_RawCharacter()
{
	global $user_info, $smcFunc, $context;

	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search'])) . '*';
	$_REQUEST['search'] = strtr($_REQUEST['search'], ['%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;']);

	$xml_data = [
		'items' => [
			'identifier' => 'item',
			'children' => [],
		],
	];

	// Find the characters
	$request = $smcFunc['db_query']('', '
		SELECT chars.id_character, chars.id_member, chars.character_name, mem.real_name
		FROM {db_prefix}characters AS chars
		INNER JOIN {db_prefix}members AS mem ON (chars.id_member = mem.id_member)
		WHERE {raw:real_name} LIKE {string:search}
			AND mem.is_activated IN (1, 11)
		LIMIT ' . ($smcFunc['strlen']($_REQUEST['search']) <= 2 ? '100' : '800'),
		[
			'real_name' => $smcFunc['db_case_sensitive'] ? 'LOWER(character_name)' : 'character_name',
			'search' => $_REQUEST['search'],
		]
	);
	while ($row = $smcFunc['db_fetch_assoc']($request))
	{
		$row['display_name'] = strtr($row['character_name'], ['&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;']);

		$xml_data['items']['children'][$row['id_member']] = [
			'attributes' => [
				'id' => $row['id_member'] . ';area=characters;char=' . $row['id_character'],
			],
			'value' => $row['display_name'],
		];<commit_msg>For raw character search, don't group by user id<commit_after><?php

if (!defined('SMF'))
	die('No direct access...');

function integrate_character_autosuggest(&$searchTypes)
{
	$searchTypes['memberchar'] = 'MemberChar';
	$searchTypes['character'] = 'Character';
	$searchTypes['rawcharacter'] = 'RawCharacter';
}

function AutoSuggest_Search_Character()
{
	global $user_info, $smcFunc, $context;

	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search'])) . '*';
	$_REQUEST['search'] = strtr($_REQUEST['search'], ['%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;']);

	$xml_data = [
		'items' => [
			'identifier' => 'item',
			'children' => [],
		],
	];

	// Find the characters
	$request = $smcFunc['db_query']('', '
		SELECT chars.id_character, chars.id_member, chars.character_name, mem.real_name
		FROM {db_prefix}characters AS chars
		INNER JOIN {db_prefix}members AS mem ON (chars.id_member = mem.id_member)
		WHERE {raw:real_name} LIKE {string:search}
			AND mem.is_activated IN (1, 11)
		LIMIT ' . ($smcFunc['strlen']($_REQUEST['search']) <= 2 ? '100' : '800'),
		[
			'real_name' => $smcFunc['db_case_sensitive'] ? 'LOWER(character_name)' : 'character_name',
			'search' => $_REQUEST['search'],
		]
	);
	while ($row = $smcFunc['db_fetch_assoc']($request))
	{
		$row['display_name'] = strtr($row['character_name'] . ' (' . $row['real_name'] . ')', ['&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;']);

		$xml_data['items']['children'][$row['id_member']] = [
			'attributes' => [
				'id' => $row['id_member'] . ';area=characters;char=' . $row['id_character'],
			],
			'value' => $row['display_name'],
		];
	}
	$smcFunc['db_free_result']($request);

	return $xml_data;
}

function AutoSuggest_Search_RawCharacter()
{
	global $user_info, $smcFunc, $context;

	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search'])) . '*';
	$_REQUEST['search'] = strtr($_REQUEST['search'], ['%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;']);

	$xml_data = [
		'items' => [
			'identifier' => 'item',
			'children' => [],
		],
	];

	// Find the characters
	$request = $smcFunc['db_query']('', '
		SELECT chars.id_character, chars.id_member, chars.character_name, mem.real_name
		FROM {db_prefix}characters AS chars
		INNER JOIN {db_prefix}members AS mem ON (chars.id_member = mem.id_member)
		WHERE {raw:real_name} LIKE {string:search}
			AND mem.is_activated IN (1, 11)
		LIMIT ' . ($smcFunc['strlen']($_REQUEST['search']) <= 2 ? '100' : '800'),
		[
			'real_name' => $smcFunc['db_case_sensitive'] ? 'LOWER(character_name)' : 'character_name',
			'search' => $_REQUEST['search'],
		]
	);
	while ($row = $smcFunc['db_fetch_assoc']($request))
	{
		$row['display_name'] = strtr($row['character_name'], ['&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;']);

		$xml_data['items']['children'][$row['id_character']] = [
			'attributes' => [
				'id' => $row['id_member'] . ';area=characters;char=' . $row['id_character'],
			],
			'value' => $row['display_name'],
		];
{'fraction_non_alphanumeric': 0.2588733311624878, 'fraction_numerical': 0.0162813415825464, 'mean_word_length': 5.211324570273003, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '4852916', 'n_tokens_mistral': 2546, 'n_tokens_neox': 2314, 'n_words': 364}