Making WordPress.org

Changeset 4992


Ignore:
Timestamp:
02/23/2017 08:17:11 AM (8 years ago)
Author:
tellyworth
Message:

Plugin directory search: improve balancing of matches against translated vs English content as backup. Props @gibrown

Fixes #2425

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php

    r4991 r4992  
    619619        if ( $args['locale'] && $args['locale'] !== 'en' && $args['locale'] !== 'en_US' ) {
    620620            $locale = $args['locale'];
     621
     622            //Because most plugins don't have any translations we need to
     623            // correct for the very low scores that locale-specific fields.
     624            // end up getting. This is caused by the average field length being
     625            // very close to zero and thus the BM25 alg discounts fields that are
     626            // significantly longer.
     627            //
     628            // As of 2017-01-23 it looked like we were off by about 10,000x,
     629            // so rather than 0.1 we use a much smaller multiplier of en content
     630            $en_boost = 0.00001;
     631            $matching_fields = array(
     632                'all_content_' . $locale,
     633                'all_content_en^' . $en_boost
     634            );
     635            $boost_phrase_fields = array(
     636                'title_' . $locale,
     637                'excerpt_' . $locale,
     638                'description_' . $locale,
     639                'title_en^' . $en_boost,
     640                'excerpt_en^' . $en_boost,
     641                'description_en^' . $en_boost,
     642                'taxonomy.plugin_tags.name',
     643            );
     644            $boost_ngram_fields = array(
     645                'title_' . $locale . '.ngram',
     646                'title_en.ngram^' . $en_boost
     647            );
     648            $boost_title_fields = array(
     649                'title_' . $locale,
     650                'title_en^' . $en_boost,
     651                'slug_text',
     652            );
     653            $boost_content_fields = array(
     654                'excerpt_' . $locale,
     655                'description_' . $locale,
     656                'excerpt_en^' . $en_boost,
     657                'description_en^' . $en_boost,
     658                'taxonomy.plugin_tags.name',
     659            );
    621660        } else {
    622             $locale = 'en';
     661            $matching_fields = array(
     662                'all_content_en'
     663            );
     664            $boost_phrase_fields = array(
     665                'title_en',
     666                'excerpt_en',
     667                'description_en',
     668                'taxonomy.plugin_tags.name',
     669            );
     670            $boost_ngram_fields = array(
     671                'title_en.ngram'
     672            );
     673            $boost_title_fields = array(
     674                'title_en',
     675                'slug_text',
     676            );
     677            $boost_content_fields = array(
     678                'excerpt_en',
     679                'description_en',
     680                'taxonomy.plugin_tags.name',
     681            );
    623682        }
    624683       
     
    635694                        'multi_match' => array(
    636695                            'query'  => $args['query'],
    637                             'fields' => 'all_content_' . $locale,
     696                            'fields' => $matching_fields,
    638697                            'boost'  => 0.1,
    639698                            'operator' => 'and',
     
    644703                            'multi_match' => array(
    645704                                'query'  => $args['query'],
    646                                 'fields' => array(
    647                                     'title_' . $locale,
    648                                     'excerpt_' . $locale,
    649                                     'description_' . $locale,
    650                                     'taxonomy.plugin_tags.name',
    651                                 ),
     705                                'fields' => $boost_phrase_fields,
    652706                                'type'  => 'phrase',
    653707                                'boost' => 2
     
    657711                            'multi_match' => array(
    658712                                'query'  => $args['query'],
    659                                 'fields' => array(
    660                                     'title_' . $locale . '.ngram'
    661                                 ),
     713                                'fields' => $boost_ngram_fields,
    662714                                'type'  => 'phrase',
    663715                                'boost' => 0.2
     
    667719                            'multi_match' => array(
    668720                                'query'  => $args['query'],
    669                                 'fields' => array(
    670                                     'title_' . $locale,
    671                                     'slug_text',
    672                                 ),
     721                                'fields' => $boost_title_fields,
    673722                                'type'  => 'best_fields',
    674723                                'boost' => 2
     
    678727                            'multi_match' => array(
    679728                                'query'  => $args['query'],
    680                                 'fields' => array(
    681                                     'excerpt_' . $locale,
    682                                     'description_' . $locale,
    683                                     'taxonomy.plugin_tags.name',
    684                                 ),
     729                                'fields' => $boost_content_fields,
    685730                                'type'  => 'best_fields',
    686731                                'boost' => 2
Note: See TracChangeset for help on using the changeset viewer.