• Resolved slipperx

    (@slipperx)


    I am also looking to improve search results. We have products that have terms such as “12 for 10” and “12 for 11” in their titles but these results when searched with or without quotes either are not returned or are far down the list. We have even disabled description and short description search to try to improve things but nothing seems to work.

    You had a similar request from Steplab a month back and provided some code to try to improve things but there is an error in the code reported as being in the line below

    if ( $term && in_array( substr( $term , 0, 6 ), array( ''', '"' ) ) && in_array( substr( $term , -6 ), array( ''', '"' ) ) ) {

    maybe you could check and fix the code provided so we can try it?

    It would be very helpful to add functionality for phrase search using quotes!

    Also when trying to change the Search placeholder text and using quotes in the text to show – the quotes are preceded with / – any way to avoid that?

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

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

    (@mihail-barinov)

    Hi,

    Please try to use this code instead:

    add_filter( 'aws_indexed_data', 'my_aws_indexed_data', 10, 2 );
    function my_aws_indexed_data( $data, $id ) {
        $content = get_post_field( 'post_content', $id );
        $data['terms']['full_title'][get_the_title( $id )] = 1;
        return $data;
    }
    
    add_filter( 'aws_search_query_array', 'my_aws_search_query_array' );
    function my_aws_search_query_array( $query ) {
        $term = esc_attr( $_REQUEST['keyword'] );
        $term = htmlspecialchars_decode( $term );
        $term = AWS_Helpers::html2txt( $term );
        $term = trim( $term );
        if ( $term && in_array( substr( $term , 0, 6 ), array( ''', '"', '"' ) ) && in_array( substr( $term , -6 ), array( ''', '"', '"' ) ) ) {
            $term = str_replace( array( ''', '"', "'", '"', '"' ), '', $term );
            $query['relevance'] = " (SUM( ( case when ( term_source = 'full_title' AND term LIKE '%{$term}%' ) then 800 else 0 end ) + ( case when ( term_source = 'full_content' AND term LIKE '%{$term}%' ) then 500 else 0 end ) )) ";
        }
        return $query;
    }
    
    add_filter( 'aws_create_index_table_sql', 'my_aws_create_index_table_sql' );
    function my_aws_create_index_table_sql( $sql ) {
        $sql = str_replace( 'term VARCHAR(50) NOT NULL DEFAULT 0,', 'term TEXT NOT NULL,', $sql );
        $sql = str_replace( 'UNIQUE KEY source_term (id,term,term_source,lang)', 'UNIQUE KEY source_term (id,term(255),term_source,lang)', $sql );
        return $sql;
    }

    Are you seeing any differences after using this code?

Viewing 1 replies (of 1 total)
  • The topic ‘Using quotes to improve search’ is closed to new replies.