/** HIGHLIGHTING **/
function relevanssi_highlight_in_docs($content)
{
    global $wp_query;
    if (is_singular() && in_the_loop()) {
        if (isset($_SERVER['HTTP_REFERER'])) {
            $referrer = preg_replace('@(http|https)://@', '', stripslashes(urldecode($_SERVER['HTTP_REFERER'])));
            $args = explode('?', $referrer);
            $query = array();
            if (count($args) > 1) {
                parse_str($args[1], $query);
            }
            if (substr($referrer, 0, strlen($_SERVER['SERVER_NAME'])) == $_SERVER['SERVER_NAME']) {
                // Local search
                if (isset($query['s'])) {
                    $q = relevanssi_add_synonyms($query['s']);
                    $content = relevanssi_highlight_terms($content, $q);
                }
            }
            if (function_exists('relevanssi_nonlocal_highlighting')) {
                $content = relevanssi_nonlocal_highlighting($referrer, $content, $query);
            }
        }
    }
    return $content;
}
/** HIGHLIGHTING **/
function relevanssi_highlight_in_docs($content)
{
    global $wp_query;
    if (is_singular() && in_the_loop()) {
        if (isset($_SERVER['HTTP_REFERER'])) {
            $referrer = preg_replace('@(http|https)://@', '', stripslashes(urldecode($_SERVER['HTTP_REFERER'])));
            $args = explode('?', $referrer);
            $query = array();
            if (count($args) > 1) {
                parse_str($args[1], $query);
            }
            if (stripos($referrer, $_SERVER['SERVER_NAME']) !== false) {
                // Local search
                if (isset($query['s'])) {
                    $q = relevanssi_add_synonyms($query['s']);
                    $highlighted_content = relevanssi_highlight_terms($content, $q);
                    if (!empty($highlighted_content)) {
                        $content = $highlighted_content;
                    }
                    // Sometimes the content comes back empty; until I figure out why, this tries to be a solution.
                }
            }
            if (function_exists('relevanssi_nonlocal_highlighting')) {
                $content = relevanssi_nonlocal_highlighting($referrer, $content, $query);
            }
        }
    }
    return $content;
}