Support » Plugin: Advanced Woo Search » Add filters to control “relevance” score + whether to multiple by count

  • Resolved urikanonov



    I’m a very happy user of your plugin but I have a problem that’s really damaging the search on my website.

    Currently the “relevance” of a search term to the search is decided by:
    $search_term_len = strlen( $search_term );
    $relevance_title = 200 + 20 * $search_term_len;
    $relevance_content = 35 + 4 * $search_term_len;
    $relevance_title_like = 40 + 2 * $search_term_len;
    $relevance_content_like = 35 + 1 * $search_term_len;

    I would like to be able to make this calculation based on the actual search term.
    For example for a jewelry website, the name of an item should hold more meaning than the type of item.
    If I have the following items:
    1. My Fiji Bracelet
    2. Some other Bracelet – Pretty Bracelet
    And I seach for “fij bracelet”, I’ll get #2 first in the results because it matched “Bracelet” twice for a “full match” making the “like” match of “fij” less valuable although it’s in fact much more important. Also, I wouldn’t want to multiply by the finding of “Bracelet” by the “count” column in the table as it’s not making the result more meaningful.

    So I ask for two things:
    1. Add filters to determine the “relevance” for each field type based on the actual search term
    2. Add a filter to decide based on the search term whether to multiply by count or not

    Thank you very much!
    The plugin is great!


Viewing 1 replies (of 1 total)
  • Plugin Author ILLID



    You can use following code snippet to add more relevance to word ‘bracelet’. After adding this code please go to plugin settings page and click ‘Clear cache’ button.

    add_filter( 'aws_search_query_array', 'my_aws_search_query_array' );
    function my_aws_search_query_array( $query ) {
        $relevance = "( case when term = "bracelet" then 800 else 0 end ) + ";
        $query['relevance'] = preg_replace( '/\(SUM\([\s\S]*?\([\s\S]*?case[\s\S]*?end[\s\S]*?\)[\s\S]*?\+/i', '$0' . $relevance, $query['relevance'] );
        return $query;


Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.