Making WordPress.org

Ticket #2425: 2425.diff

File 2425.diff, 3.8 KB (added by gibrown, 8 years ago)
  • wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php

     
    604604
    605605                if ( $args['locale'] && $args['locale'] !== 'en' && $args['locale'] !== 'en_US' ) {
    606606                        $locale = $args['locale'];
     607
     608                        //Because most plugins don't have any translations we need to
     609                        // correct for the very low scores that locale-specific fields.
     610                        // end up getting. This is caused by the average field length being
     611                        // very close to zero and thus the BM25 alg discounts fields that are
     612                        // significantly longer.
     613                        //
     614                        // As of 2017-01-23 it looked like we were off by about 10,000x,
     615                        // so rather than 0.1 we use a much smaller multiplier of en content
     616                        $en_boost = 0.00001;
     617                        $matching_fields = array(
     618                                'all_content_' . $locale,
     619                                'all_content_en^' . $en_boost
     620                        );
     621                        $boost_phrase_fields = array(
     622                                'title_' . $locale,
     623                                'excerpt_' . $locale,
     624                                'description_' . $locale,
     625                                'title_en^' . $en_boost,
     626                                'excerpt_en^' . $en_boost,
     627                                'description_en^' . $en_boost,
     628                                'taxonomy.plugin_tags.name',
     629                        );
     630                        $boost_ngram_fields = array(
     631                                'title_' . $locale . '.ngram',
     632                                'title_en.ngram^' . $en_boost
     633                        );
     634                        $boost_title_fields = array(
     635                                'title_' . $locale,
     636                                'title_en^' . $en_boost,
     637                                'slug_text',
     638                        );
     639                        $boost_content_fields = array(
     640                                'excerpt_' . $locale,
     641                                'description_' . $locale,
     642                                'excerpt_en^' . $en_boost,
     643                                'description_en^' . $en_boost,
     644                                'taxonomy.plugin_tags.name',
     645                        );
    607646                } else {
    608                         $locale = 'en';
     647                        $matching_fields = array(
     648                                'all_content_en'
     649                        );
     650                        $boost_phrase_fields = array(
     651                                'title_en',
     652                                'excerpt_en',
     653                                'description_en',
     654                                'taxonomy.plugin_tags.name',
     655                        );
     656                        $boost_ngram_fields = array(
     657                                'title_en.ngram'
     658                        );
     659                        $boost_title_fields = array(
     660                                'title_en',
     661                                'slug_text',
     662                        );
     663                        $boost_content_fields = array(
     664                                'excerpt_en',
     665                                'description_en',
     666                                'taxonomy.plugin_tags.name',
     667                        );
    609668                }
    610669               
    611670                ///////////////////////////////////////////////////////////
     
    620679                                        'must' => array(
    621680                                                'multi_match' => array(
    622681                                                        'query'  => $args['query'],
    623                                                         'fields' => 'all_content_' . $locale,
     682                                                        'fields' => $matching_fields,
    624683                                                        'boost'  => 0.1,
    625684                                                        'operator' => 'and',
    626685                                                ),
     
    629688                                                array(
    630689                                                        'multi_match' => array(
    631690                                                                'query'  => $args['query'],
    632                                                                 'fields' => array(
    633                                                                         'title_' . $locale,
    634                                                                         'excerpt_' . $locale,
    635                                                                         'description_' . $locale,
    636                                                                         'taxonomy.plugin_tags.name',
    637                                                                 ),
     691                                                                'fields' => $boost_phrase_fields,
    638692                                                                'type'  => 'phrase',
    639693                                                                'boost' => 2
    640694                                                        ),
     
    642696                                                array(
    643697                                                        'multi_match' => array(
    644698                                                                'query'  => $args['query'],
    645                                                                 'fields' => array(
    646                                                                         'title_' . $locale . '.ngram'
    647                                                                 ),
     699                                                                'fields' => $boost_ngram_fields,
    648700                                                                'type'  => 'phrase',
    649701                                                                'boost' => 0.2
    650702                                                        ),
     
    652704                                                array(
    653705                                                        'multi_match' => array(
    654706                                                                'query'  => $args['query'],
    655                                                                 'fields' => array(
    656                                                                         'title_' . $locale,
    657                                                                         'slug_text',
    658                                                                 ),
     707                                                                'fields' => $boost_title_fields,
    659708                                                                'type'  => 'best_fields',
    660709                                                                'boost' => 2
    661710                                                        ),
     
    663712                                                array(
    664713                                                        'multi_match' => array(
    665714                                                                'query'  => $args['query'],
    666                                                                 'fields' => array(
    667                                                                         'excerpt_' . $locale,
    668                                                                         'description_' . $locale,
    669                                                                         'taxonomy.plugin_tags.name',
    670                                                                 ),
     715                                                                'fields' => $boost_content_fields,
    671716                                                                'type'  => 'best_fields',
    672717                                                                'boost' => 2
    673718                                                        ),