Making WordPress.org

Changeset 10117


Ignore:
Timestamp:
08/05/2020 01:49:48 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Search: Transform Block Directory block searches over to ElasticSearch.

Block Searches might be less reliable today while this change is finalised, a few other index alterations are needed for all current blocks to be properly indexed.
Some changes to the boosting phrases will also be needed most likely once this is finalised and we can do some proper testing.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-query-plugins.php

    r10115 r10117  
    6666                }
    6767
    68                 // Temporary hacky block search
    69                 $block_search = trim( strtolower( $request->get_param( 'block' ) ) );
     68                // Block Directory searches
     69                $block_search = $request->get_param( 'block' );
    7070                if ( $block_search ) {
    71                         $meta_query = array(
    72                                 'relation' => 'AND',
    73                                 array(
    74                                         'key' => 'block_files',
    75                                         'compare' => 'EXISTS',
    76                                 ),
    77                                 array(
    78                                         'relation' => 'OR',
    79                                         array(
    80                                                 'key' => 'block_name',
    81                                                 'value' => '^' . preg_quote( $block_search ),
    82                                                 'compare' => 'RLIKE',
    83                                         ),
    84                                         array(
    85                                                 'key' => 'block_name',
    86                                                 'value' => '/' . $block_search, // search following the slash
    87                                                 'compare' => 'LIKE',
    88                                         ),
    89                                         array(
    90                                                 'key' => 'block_title',
    91                                                 'value' => $block_search, // search in title
    92                                                 'compare' => 'LIKE',
    93                                         ),
    94                                         array(
    95                                                 'key' => 'header_name',
    96                                                 'value' => $block_search, // search in plugin title
    97                                                 'compare' => 'LIKE',
    98                                         ),
    99                                 )
    100                         );
    101 
    102                         // Limit the search to the Block section
    103                         $query[ 'meta_query' ] = $meta_query;
    104                         $query[ 'tax_query' ] = array(
    105                                 array(
    106                                         'taxonomy' => 'plugin_section',
    107                                         'field' => 'slug',
    108                                         'terms' => 'block',
    109                                 )
    110                         );
     71                        $query['s'] = $block_search;
     72                        $query['block_search'] = true;
    11173                }
    11274
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php

    r10115 r10117  
    430430                }
    431431
     432                // Block Search.
     433                if ( !empty( $query->query['block_search'] ) ) {
     434                        $es_wp_query_args['block_search'] = $query->query['block_search'];
     435
     436                        // Limit to the Block Tax.
     437                        $es_wp_query_args['filters'][] = array(
     438                                'term' => array(
     439                                        'taxonomy.plugin_section.name' => array(
     440                                                'value' => 'block'
     441                                        )
     442                                )
     443                        );
     444                }
     445
    432446                $es_wp_query_args['locale'] = $query->get( 'locale' ) ?: get_locale();
    433447
    … …  
    763777                }
    764778
     779                $is_block_search = ! empty( $args['block_search'] );
     780
    765781                if ( $args['locale'] && $args['locale'] !== 'en' && substr( $args['locale'], 0, 3 ) !== 'en_' ) {
    766782                        $locale = $args['locale'];
    … …  
    788804                                'taxonomy.plugin_tags.name',
    789805                        );
     806                        if ( $is_block_search ) {
     807                                $boost_phrase_fields[] = 'block_title_' . $locale;
     808                                $boost_phrase_fields[] = 'block_title_en^' . $en_boost;
     809                        }
    790810                        $boost_ngram_fields   = array(
    791811                                'title_' . $locale . '.ngram',
    … …  
    797817                                'slug_text',
    798818                        );
     819                        if ( $is_block_search ) {
     820                                $boost_title_fields[] = 'block_title_' . $locale;
     821                                $boost_title_fields[] = 'block_title_en^' . $en_boost;
     822                                $boost_title_fields[] = 'block_name';
     823                        }
    799824                        $boost_content_fields = array(
    800825                                'excerpt_' . $locale,
    … …  
    814839                                'taxonomy.plugin_tags.name',
    815840                        );
     841                        if ( $is_block_search ) {
     842                                $boost_phrase_fields[] = 'block_title_en';
     843                        }
    816844                        $boost_ngram_fields   = array(
    817845                                'title_en.ngram',
    … …  
    821849                                'slug_text',
    822850                        );
     851                        if ( $is_block_search ) {
     852                                $boost_title_fields[] = 'block_title_en';
     853                                $boost_title_fields[] = 'block_name';
     854                        }
    823855                        $boost_content_fields = array(
    824856                                'excerpt_en',
Note: See TracChangeset for help on using the changeset viewer.