• How can I highlight whole search terms with spaces? If I got a search term like i.e. &highlight=your issue is visual I want to highlight that complete search term. Actually the complete search term is highlighted in the results but also all parts of it in my example also your, issue, is and visual are highlighted also.

    • This topic was modified 3 years, 9 months ago by skar666.
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Search for the phrase, and Relevanssi will do the highlighting as a phrase. If you search for "your issue is visual", Relevanssi will only return posts with that exact phrase and will only highlight the complete phrase.

    The default behaviour is to consider the search terms as independent of each other.

    Thread Starter skar666

    (@skar666)

    But that’s the problem. The exact phrase with spaces is highlighted but also all parts of it too. What default settings are correct to prevent that not single parts of the search term are highlighted?

    • This reply was modified 3 years, 9 months ago by skar666.
    Plugin Author Mikko Saari

    (@msaari)

    If you search for the phrase, using quotes, Relevanssi should not highlight individual words, only the full phrase. So please confirm: are you searching for the phrase ("your issue is visual" and not your issue is visual) and still seeing highlights?

    If that’s indeed the case, is the phrase matching working at all? Do you only get results that include the exact phrase, or are you also seeing results that have individual words of the phrase?

    If you do not have quotes around the search phrase, then everything is working as expected.

    Thread Starter skar666

    (@skar666)

    There are no quotes in my URL with the highlight parameter. How I can use quotes?

    • This reply was modified 3 years, 9 months ago by skar666.
    Plugin Author Mikko Saari

    (@msaari)

    There are quotes in the URL if you type them in the search query. Nothing will add them automatically.

    If you want to, it’s possible to force all search queries to be phrases by setting the sentence query variable, but that’s rarely a good idea, as it will make searching much harder overall.

    Thread Starter skar666

    (@skar666)

    It don’t work for me. Please have a look on that url:

    https://dtco-info.com/?page_id=239665

    Please search for that term “Lenk- und Ruhezeiten” and open the first result.

    Plugin Author Mikko Saari

    (@msaari)

    To me this seems to work correctly: when I search for "lenk- und ruhezeiten", I get to https://dtco-info.com/?s=%22lenk-+und+ruhezeiten%22&post_types=page and there clicking the link takes me to https://dtco-info.com/?page_id=237898&highlight=%22lenk-%20und%20ruhezeiten%22 where there are no extraneous highlights.

    Thread Starter skar666

    (@skar666)

    Is there any way to automatically quote the search term without a user having to manually enter the quotation marks?

    Plugin Author Mikko Saari

    (@msaari)

    Thread Starter skar666

    (@skar666)

    Ok. I’ve added that snippet of code to my functions.php but nothing happens:

    add_filter( 'relevanssi_modify_wp_query', 'rlv_force_sentence' );
    /**
     * Enables the <code>sentence</code> parameter in Releavnssi queries.
     *
     * @param WP_Query $query The query object.
     *
     * @return WP_Query The modified query object.
     */
    function rlv_force_sentence( $query ) {
      $query->set( 'sentence', true );
      return $query;
    }
    Plugin Author Mikko Saari

    (@msaari)

    Oh, it’s doing something: try searching for lenk ruhezeiten. No results, because you’re looking for a phrase now.

    It’s not solving the highlight problem, though. That’s something I probably need to fix in Relevanssi, to make Relevanssi add the quotes when the sentence parameter is enabled. I’ll make that change in the next version.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Highlight terms with spaces’ is closed to new replies.