• Resolved professor99

    (@professor99)


    There are a couple of problems with the “Highlight query terms in documents from local searches” option.

    Problem 1

    Clicking on any link on the search results page will result in the search terms being highlighted on the referenced page. This includes menu items and sidebar items. Conceptually this should just happen on the listed search items.

    This happens because Relevansi hooks the wordpress filter “the_content” and does the highlighting based on if the search page is the http_referrer.

    One solution is to have Relevansi display the search results and add a Relevansi query flag to identify Relanvansi search links. This can be done by Relevansi providing it’s own version of search.php by using the WordPress ‘template_include’ or ‘search_template’ (see get_query_template) filters.

    However this isn’t a huge problem as it’s only effect is highlighting of some text on the affected page.

    Problem 2

    This option breaks script (javascript etc) and style (css) tags embedded within content if it contains the search item.

    This has been confirmed in version 3.1.3 and 3.1.4 of Relenvansi and may exist in previous versions.

    The solution is to update the function relevanssi_highlight_terms in excerpts_highlights.php as follows.

    foreach ($terms as $term) {
    		$pr_term = preg_quote($term, '/');
    		if ($word_boundaries) {
    			$excerpt = preg_replace("/(\b$pr_term|$pr_term\b)(?!([^<]+)?(>|<\/script>|<\/style>))/iu", $start_emp_token . '\\1' . $end_emp_token, $excerpt);
    		}
    		else {
    			$excerpt = preg_replace("/($pr_term)(?!([^<]+)?(>|<\/script>|<\/style>))/iu", $start_emp_token . '\\1' . $end_emp_token, $excerpt);
    		}
    		// thanks to http://pureform.wordpress.com/2008/01/04/matching-a-word-characters-outside-of-html-tags/
    	}

    http://wordpress.org/extend/plugins/relevanssi/

Viewing 1 replies (of 1 total)
  • Plugin Author Mikko Saari

    (@msaari)

    As to your problem 1, I’m not particularly interested in providing a search results template with Relevanssi – that’s a can of worms I’d rather not open. But yes, there’s a bit of a problem, but I don’t have a particularly good solution to it. A better filter to hook on would be nice.

    Re problem 2, I’ll be happy to include your fix in the next versio. Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘Problems with "Highlight query terms in documents from local searches" option’ is closed to new replies.