• Resolved neilt17

    (@neilt17)


    I have over 1500 video snippets on my site each of which are titled by usually a single word. Users need to search by a word such as “I”, “cat”, “tree”. When a user searches by a shorter word they get a lot of results which are ordered alphabetically, and the video for the word they typed may well be embedded far down in the search list (for example on page 30 of the results).

    To get over this problem, I can install a plugin like “Ivory Search” which gives much more relevant results for the search term, however this means I don’t get the nice search results page that All-In-One video gallery produces.

    Is there a way of configuring All-In-One video gallery to give more relevant search results? Or is there a plugin that could make that happen?

    For example search for “me”:
    Using All-In-One video search
    Using Ivory search

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor wpvideogallery

    (@wpvideogallery)

    Kindly try adding the following code to the bottom of your theme’s functions.php file,

    add_filter( 'posts_search', 'my_search_is_perfect', 20, 2 );
    function my_search_is_perfect( $search, $wp_query ) {
        global $wpdb;
    
        if ( empty( $search ) )
            return $search;
    
        $q = $wp_query->query_vars;
        $n = !empty( $q['exact'] ) ? '' : '%';
    
        $search = $searchand = '';
    
        foreach ( (array) $q['search_terms'] as $term ) {
            $term = esc_sql( like_escape( $term ) );
    
            $search .= "{$searchand}($wpdb->posts.post_title REGEXP '[[:<:]]{$term}[[:>:]]') OR ($wpdb->posts.post_content REGEXP '[[:<:]]{$term}[[:>:]]')";
    
            $searchand = ' AND ';
        }
    
        if ( ! empty( $search ) ) {
            $search = " AND ({$search}) ";
            if ( ! is_user_logged_in() )
                $search .= " AND ($wpdb->posts.post_password = '') ";
        }
    
        return $search;
    }
    Thread Starter neilt17

    (@neilt17)

    That’s perfect – thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Search relevance’ is closed to new replies.