WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
[resolved] Problems with "Highlight query terms in documents from local searches" option (2 posts)

  1. professor99
    Member
    Posted 1 year ago #

    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/

  2. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.