Okay, numerous hours later I've almost got a solution to this.
Edit: Now have got a solution, make sure you read the updates at the bottom of answer.
Probably will prove very useful to any stores that require SKU codes to be searchable or have a number of products that contain special characters because now at last, by implementing the below, Magento's search will return results for these search queries.
After some debugging, I identified that the URL's were being encoded (twice) in Url.php located at /app/code/core/Mage/Core/Model.
$query = http_build_query($params, '', $escape ? '&' : '&');
As pointed out in function getSearchUrl in /app/code/core/Mage/CatalogSearch/Block/Term.php.
public function getSearchUrl($obj)
{
$url = Mage::getModel('core/url');
/*
* url encoding will be done in Url.php http_build_query
* so no need to explicitly called urlencode for the text
*/
$url->setQueryParam('q', $obj->getName());
return $url->getUrl('catalogsearch/result');
}
So at this point, I knew I needed to reverse urlencode and output this result instead of the escaped query for search.
I was able to reverse this process using the following:-
$noescape = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($this->_queryText));
Adding this to function getQueryText in /app/code/core/Mage/CatalogSearch/Helper/Data.php then allowed me to return the non escaped query text with $noescape so I simply add a new function in Data.php underneath getEscapedQueryText like so:-
/**
* Retrieve search query without escaping special characters
*
* @return string
*/
public function getNoEscapedQueryText()
{
return $noescape;
}
Now all I need to do is figure what code is outputting the query in the URL so I can modify this to use $noescape but struggling to find this at present. Will update my answer as soon as I find it.
Update
I know that return $this->_queryText; is what is outputting the search query in the URL now, I just haven't figured out how to incorporate the above into this output (I haven't managed to figure out the correct syntax).
Currently fiddling about with variations of
return $this->preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($this->_queryText));
and
return $noescape($this->_queryText);
Update 2
$noescape above can now be ignored as we can just modify return $this->_queryText; directly with:-
return $this->_queryText = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($this->_queryText));
End result is that we can now use special characters in Magento's search field that returns results and doesn't escape them to %252F2 for example. The URL's will still contain the likes of %252F2 but it retains the special characters in the search field via getQueryText so it still resolves the problem.