• Resolved cheyenne711

    (@cheyenne711)


    add_filter( 'aws_search_query_array', 'my_aws_search_query_array5' );
    function my_aws_search_query_array5( $query ) {
        $product_id = array( 4101, 4096, 4085, 4080, 4075, 4070, 4065, 4060, 4054, 4045, 4040, );
        $product_id_string = implode( ',', $product_id );
        if ( strpos( $query['search'], 'wire wheel' ) !== false ) {
            $relevance = "( case when ID IN ({$product_id_string}) then 900 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;
    }

    Hi, I used the above code to try and get certain products to show first when doing a search for wire wheel and it doesn’t appear to be having any effect. Could you please let me know what I am doing wrong?

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    The problem here is in part

    strpos( $query['search'], 'wire wheel' ) !== false 

    When preparing search query plugin split such strings word by word. So Instead your code snippet can look like that:

    add_filter( 'aws_search_query_array', 'my_aws_search_query_array5' );
    function my_aws_search_query_array5( $query ) {
        $product_id = array( 4101, 4096, 4085, 4080, 4075, 4070, 4065, 4060, 4054, 4045, 4040, );
        $product_id_string = implode( ',', $product_id );
        if ( strpos( $query['search'], 'wire' ) !== false && strpos( $query['search'], 'wheel' ) !== false  ) {
            $relevance = "( case when ID IN ({$product_id_string}) then 900 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;
    }

    Regards

    Thread Starter cheyenne711

    (@cheyenne711)

    That worked. Thank you so much!

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

The topic ‘Search Results’ is closed to new replies.