Ya it is just copy/pasta more or less I don't mind changing it though. htmlderpchars() doesn't seem like its required but I'll keep drupal_encode_path for the term, or do you reckon the escape function from the Solr library would be better?