<?php

$page['search']['handler'] = 'searchHandler_Local';

function searchHandler_local()
{
	try
	{
		$terms = trim (genericAssertion ('q', 'string'));
	}
	catch (InvalidRequestArgException $irae)
	{
		$terms = '';
	}
	if (preg_match("/:/", $terms))
	{
		$pattern = '/\:/';	// Remove colons so WWPN/WWNN will find a match
		$replace = '';
		$terms = preg_replace($pattern, $replace, $terms);
	}
	if ($terms == '')
	{
		showError ('Search string cannot be empty.');
		redirectUser (buildRedirectURL ('index', 'default'));
	}

	try
	{
		parseSearchTerms ($terms);
		// Discard the return value as searchEntitiesByText() and its retriever
		// functions expect the original string as the parameter.
	}
	catch (InvalidArgException $iae)
	{
		showError ($iae->getMessage());
		redirectUser (buildRedirectURL ('index', 'default'));
	}

	renderSearchResults ($terms, searchEntitiesByText ($terms));
}
