• Resolved SventB

    (@sventb)


    I want to include underscores in search, e.g. when searching for “array_values” I want to find pages where exactly this word occurs and not the words “array” and “values”.

    To archive that, I have to use filter “relevanssi_punctuation_filter” to replace underscores with some placeholder (e.g. “UNDERSCORETAIKASANA”):

    '_' => 'UNDERSCORETAIKASANA'

    But then, this placeholder has to be replaced back to underscore:

    $a = str_replace( 'DESIMAALITAIKASANA', '.', $a ); // This is already present in lib/common.php
    $a = str_replace( 'UNDERSCORETAIKASANA', '_', $a ); // This is new

    Can you please add this? ??

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

    (@msaari)

    No, because you can already do this with filters. I have the same need on Relevanssi.com myself, and I have this:

    add_filter('relevanssi_remove_punctuation', 'rlv_keep_underscores_pre', 9);
    function rlv_keep_underscores_pre($a) {
    	$a = str_replace('_', 'UNDERSCOREUNDERSCORE', $a);
    	return $a;
    }
    
    add_filter('relevanssi_remove_punctuation', 'rlv_keep_underscores_post', 11);
    function rlv_keep_underscores_post($a) {
    	$a = str_replace('UNDERSCOREUNDERSCORE', '_', $a);
    	return $a;
    }

    However, in most cases, you’d actually do fine with just this:

    add_filter( 'relevanssi_punctuation_filter', function( $punct ) { $punct['_'] = ''; return $punct; } );

    That’s likely enough, because in practise there’s few cases where “array_values” and “arrayvalues” would need to be separate things.

    Thread Starter SventB

    (@sventb)

    Hi Mikko,

    thank you, this helped.

    I’ld like to give s.th. in return but the “donate” link leads to purchasing Relevanssi Premium, which I don’t need ??

    Plugin Author Mikko Saari

    (@msaari)

    A review would do well. Thanks!

    Thread Starter SventB

    (@sventb)

    Hi Mikko,
    I finally gave a review: https://www.ads-software.com/support/topic/helpful-plugin-and-great-support-3/
    But that’s not enough, give me your PayPal name and I can donate ??

    Plugin Author Mikko Saari

    (@msaari)

    I’m sorry, but telling you my email here would be a breach of forum rules, so I can’t do that.

    I’m fine with the review, but if you really insist, I’m msaari on Making WordPress Slack, so you can drop me a note there.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search term with underscore’ is closed to new replies.