• Resolved hatschiii

    (@hatschiii)


    Content, titles, coment text, tag weight, category weight… great thingts to customize the search results.

    What I’m missing is a time weight. I want prioritize newer blog post in the searchresults.

    Is there any way to do so?

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

    (@msaari)

    Yes. There’s an option for that in Relevanssi Premium, or you can do it with some code. See “Date-based weight” here: https://www.relevanssi.com/knowledge-base/relevanssi-match/

    Thread Starter hatschiii

    (@hatschiii)

    Thanks Mikko

    Thread Starter hatschiii

    (@hatschiii)

    Hm…. tha’ts not exacty what I’m looking for. It gives a boost for pages newer than 1 week.

    What I want is a dynamic date weight. Sure I can set many many if..

    < 1 day
    < 2 days
    < 3 days
    < 4 days

    < 365 days

    But this is not a nice practical solution with much code (affects load time)

    Any ideea how to get it done somehow else?

    Plugin Author Mikko Saari

    (@msaari)

    That’s still the method you’d need to use. Instead of the fixed date modifier, you can use a function that converts the date to a weight multiplier.

    Perhaps count the age of the post in days, then subtract that from a suitable number? Something like that, so that a fresh post gets a multiplier of 365 and anything at least a year old gets a multiplier of 1.

    There are many approaches to this, but no matter how you do it, you’d still need to write the relevanssi_match filter hook that adjusts the weight based on the age of the post.

    Thread Starter hatschiii

    (@hatschiii)

    I’m a marketing guy, not a programmer… sounds like this is a bit to tricky for me!?

    Plugin Author Mikko Saari

    (@msaari)

    Well, you can always hire a programmer… but here’s a more dynamic time-based weight system for you, add this to your theme functions.php file:

    add_filter( 'relevanssi_match', 'rlv_dynamic_time_weights' );
    function rlv_dynamic_time_weights( $match ) {
    	$now       = date_create( 'now' );
    	$post_date = date_create( get_the_time( 'Y-m-d', $match->doc ) );
    	$diff_days = $now->diff( $post_date, true )->format( '%a' );
    
    	if ( $diff_days < 1 ) {
    		$diff_days = 1;
    	}
    	$date_weight_multiplier = 500 / $diff_days;
    	$match->weight = $match->weight * $date_weight_multiplier;
    
    	return $match;
    }
    Thread Starter hatschiii

    (@hatschiii)

    Cool 🙂 Thanks Mikko!!!

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

The topic ‘Time weight’ is closed to new replies.