Support » Plugin: Site Reviews » Remove Bayesian and filter based on Average Rating using Filter Plugin

  • Resolved galatanuadrian27

    (@galatanuadrian27)


    Hello!

    I am using Search And Filter plugin: wordpress.org/plugins/search-filter/, on this page: Casinos List .

    Problem 1:

    Problem that i am facing is for the CPT items that have not been rated. They are not shown. I am sorting them using meta key: _glsr_ranking .

    I tried to add a hook:

    /* Do something with the data entered */
    add_action( 'save_post', 'myplugin_save_postdata' );
    
    /* When the post is saved, saves our custom data */
    function myplugin_save_postdata( $post_id ) {
    
      // First we need to check if the current user is authorised to do this action. 
      if ( 'page' == $_POST['cpt_sites'] ) {
        if ( ! current_user_can( 'edit_page', $post_id ) )
            return;
      } else {
        if ( ! current_user_can( 'edit_post', $post_id ) )
            return;
      }
    
      $mydata = '5'; // Do something with $mydata 
    
      update_post_meta( $post_id, '_glsr_ranking', $mydata );
    }

    … but this doesnt work, _glsr_ranking haves value of 5 in the database for the new CPT item, but because the CPT Item have 0 ratings (it was not rated by a real person), the stars are empty. What can i do here?

    Problem 2:
    Another problem that i have, is the average rating for each CPT item. Using Bayesian calculation its not good for this website. All products will have 3.7 rating, even if 2-3 people will rate all of them 5 Stars. I tried to change this behaviour by changing this file into your plugin (plugin/Rating.php):

    Original:

    public function getRankingImdb( array $reviews, $confidencePercentage = 70 )
    	{
    		// Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
    		$bayesMinimal = 10; // confidence
    		// Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
    		// This could also be the average score of all items instead of a fixed value.
    		$bayesMean = ( $confidencePercentage / 100 ) * static::MAX_RATING; // prior, 70% = 3.5
    		$numOfReviews = count( $reviews );
    		$avgRating = $this->getAverage( $reviews );
    		return $avgRating > 0
    			? (( $bayesMinimal * $bayesMean ) + ( $avgRating * $numOfReviews )) / ( $bayesMinimal + $numOfReviews )
    			: 0;
    	}

    My edit:

    public function getRankingImdb( array $reviews, $confidencePercentage = 70 )
    	{
    		// Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior.
    		$bayesMinimal = 100; // confidence
    		// Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error.
    		// This could also be the average score of all items instead of a fixed value.
    		$bayesMean = ( $confidencePercentage / 100 ) * static::MAX_RATING; // prior, 70% = 3.5
    		$numOfReviews = count( $reviews );
    		$avgRating = $this->getAverage( $reviews );
    		return $avgRating > 0
    			? $avgRating
    			: 0;
    	}

    This change has helped me if for example 3 people give 5 Stars, the average will be 5 stars (with Bayesian it was 3.7).

    Problem 3:

    Ability to change the average rating in the backend?

    I want to do a donation, where i can do that?

    Thanks alot!

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    Hi @galatanuadrian27!

    I will address problem #2 first:

    The bayesian algorithm is only used to calculate the ranking of a review, not to calculate its average rating. For example, the [site_reviews_summary] shortcode displays the average rating based on the ratings of the reviews, it is not based on the bayesian ranking.

    The _glsr_ranking meta_value should only really be used for sorting reviews that have been assigned to a page. The value is also updated every time a new assigned review is submitted.

    This brings me to problem #1:

    Because the ‘_glsr_ranking’ meta_value is only give to a review that has been assigned to a page, it is possible that not all reviews will have a ‘_glsr_ranking’ meta_key saved. For this reason, in order to sort reviews properly you will have to use a meta_query as shown in this example here.

    I have not looked into it yet, but it’s possible that the “Search And Filter” plugin provides a filter hook to allow you to modify the meta_query used by the plugin to allow for this.

    Finally, to answer problem #3:

    It is not possible at the moment to modify the average rating algorithm. However, the calculation used is pretty standard and is done using the following formula:
    (sumOfAllReviewRatings / numberOfReviews)

    So for example, suppose you have a total of six reviews. Four of them have a 5-star rating, one has a 4-star rating, and one has a 3-star rating. The formula would work like this:
    ((5+5+5+5+4+3)/6) = Average rating of 4.5 stars

    I hope this helps you.

    Donations are always appreciated. You can find the “Donate to this plugin” button on the WordPress plugin page at the bottom of the sidebar.

    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    Plugin Author Gemini Labs

    (@geminilabs)

    If you send me an example of how you are using the Search & Filter plugin shortcode (so I can replicate it), I can see if I can put together an example function for you to paste into your active theme’s functions.php file to solve problem #1.

    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    Thread Starter galatanuadrian27

    (@galatanuadrian27)

    Hello!

    Thank you for your answers. Here is how i am using the Search & Filter plugin for this page: Bonuses

    This is in the backend, using Visual Builder plugin:

    Image

    This is the template that i use for the filter (i made it txt file so you can see whats in it):

    Search And Filter Custom Template

    This are the settings for the Sort Filter:

    Sort filter settings

    Display Results Settings

    Let me know if all of these infos are ok. If you need, i can give you the admin login creds, so you can have full control šŸ™‚

    I made the donation now, very good job with this plugin, i think its the best out here.

    Thanks alot!

    Late edit***
    Its there a option to delete all ratings/and plugin data from the database? I think it will be easier for you to see all the results from scratch.

    Late late edit***
    I deleted now all ratings from the backend page: /wp-admin/edit.php?post_type=site-review.

    Late late late edit*** LOL
    What i dont understand, is if i give 5 stars rating to one bonus, the _glsr_ranking value will be 3.75. Why?

    Example here: Example

    • This reply was modified 3 years, 8 months ago by galatanuadrian27. Reason: Added target _blank to the Casino page link
    • This reply was modified 3 years, 8 months ago by galatanuadrian27.
    • This reply was modified 3 years, 8 months ago by galatanuadrian27.
    • This reply was modified 3 years, 8 months ago by galatanuadrian27.
    Plugin Author Gemini Labs

    (@geminilabs)

    The reason the “_glsr_ranking” value will be 3.75 is because the bayesian algorithm takes into account unknowns and makes assumptions based on those unknowns. As it gets more data (more ratings) it can make better assumptions.

    For example, a post with four 5-star reviews is obviously more valuable than a post with only one 5-star review. Additionally, a post with two 4-star reviews and four 5-star reviews is also probably more valuable than a post with only two 5-star reviews. The bayesian algorithm takes all of this into account.

    Also just to clarify, the “_glsr_ranking” value only exists to allow you to rank (or sort) rated posts. Its value has nothing to do with the average rating value.

    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    Plugin Author Gemini Labs

    (@geminilabs)

    Unfortunately, I do not have access to the Search & Filter Pro plugin. However, if you don’t mind providing me with a login I can help you directly there. You can send details to site-reviews[at]geminilabs.io

    Otherwise the most help I can give you is a pointer in the right direction. The Search & Filter Pro docs show you how you can customize the WP_Query. Here is an example of how this would be used in your active theme’s functions.php file:

    
    /**
     * @return $queryArgs
     */
    add_filter( 'sf_edit_query_args', function( $queryArgs, $searchFormId ) {
    
        if( $searchFormId == 8357 ) {
            // verify $queryArgs values here to make sure the query should be modified
            // if sorting by _glsr_ranking then modify the meta_query
        }
        return $queryArgs;
    }, 20, 2 );

    When sorting by ranking, you will want the search form $wp_query to use a meta_query similar to this:

    
    $query['meta_query'] = [
        'relation' => 'OR',
        ['key' => '_glsr_ranking', 'compare' => 'EXISTS'],
        ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'],
    ];
    $query['order'] = 'DESC';
    $query['orderby'] = 'meta_value';
    
    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    Plugin Author Gemini Labs

    (@geminilabs)

    I have added the following filter hook to your active theme’s functions.php file which solves the sorting issue with the Search & Filter Pro plugin:

    
    /**
     * Fix to display all reviews when sorting by rank
     * @return array $query
     */
    add_filter( 'sf_edit_query_args', function( $query ) {
        if( !empty( $query['meta_key'] ) && $query['meta_key'] == '_glsr_ranking' ) {
            unset( $query['meta_key'] ); 
            $query['meta_query'] = [
                'relation' => 'OR',
                ['key' => '_glsr_ranking', 'compare' => 'EXISTS'],
                ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'],
            ];
        }
        return $query;
    }, 20 );
    
    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    Thread Starter galatanuadrian27

    (@galatanuadrian27)

    Hi! That made it to work perfectly!!! Thanks a lot for your help!

    Thread Starter galatanuadrian27

    (@galatanuadrian27)

    Also another question.

    Can i automatically add a 5 star rating when a post is created?

    Plugin Author Gemini Labs

    (@geminilabs)

    It is possible to disable the star rating on the submission form and automatically set a 5-star rating to every review submitted.

    Step 1:
    https://github.com/geminilabs/site-reviews/wiki/How-to-disable-the-star-rating-on-the-submission-form

    Step 2:

    /**
     * Set a 5-star rating for every review submitted
     * @return void
     */
    add_action( 'site-reviews/local/review/create', function( $postData, $metaData, $postId ) {
        update_post_meta( $postId, 'rating', '5' );
    }, 10, 3 );
    
    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    Thread Starter galatanuadrian27

    (@galatanuadrian27)

    Hello again!

    Any idea why on this page, the Sorting based on ratings is wrong?

    http://ndbdev.eu/oldVersion/no-deposit-bonuses/

    You have the backend credentials, if you want to take a deeper look.

    Thanks!

    Plugin Author Gemini Labs

    (@geminilabs)

    I’m not sure what you mean, it works for me.

    Here are some screenshots:

    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    Thread Starter galatanuadrian27

    (@galatanuadrian27)

    Plugin Author Gemini Labs

    (@geminilabs)

    This is working as intended.

    A post with two 5-star reviews and a 4-star review will have a higher bayesian score than a post with only two 5-star reviews (which is the case on that page).

    • The average rating is a number between 1 and 5 or a fraction in-between.
    • The bayesian ranking a score assigned to a post that determines how it ranks in relation to the rest of the posts. The bayesian ranking takes into account more than just the average rating, it also takes into account how many ratings have been given for the post, and what rating is likely to be given it in the future based on the existing ratings.

    It seems what you are looking for is the ability to sort by the average rating instead of by the bayesian ranking.

    If this is correct, please wait until the next version at which point I will give you further directions.

    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    Plugin Author Gemini Labs

    (@geminilabs)

    Please update the plugin to v2.13.1.

    Once you have done that, edit the function I added to your active theme’s functions.php file and change _glsr_ranking to _glsr_average.

    This will sort the reviews by the average rating instead of the bayesian ranking.

    • This reply was modified 3 years, 8 months ago by Gemini Labs.
    Thread Starter galatanuadrian27

    (@galatanuadrian27)

    Awesome!!!

    That made it to work!

    Thanks a lot!

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Remove Bayesian and filter based on Average Rating using Filter Plugin’ is closed to new replies.