Ticket #2425: 2425.diff
File 2425.diff, 3.8 KB (added by , 8 years ago) |
---|
-
wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php
604 604 605 605 if ( $args['locale'] && $args['locale'] !== 'en' && $args['locale'] !== 'en_US' ) { 606 606 $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 ); 607 646 } 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 ); 609 668 } 610 669 611 670 /////////////////////////////////////////////////////////// … … 620 679 'must' => array( 621 680 'multi_match' => array( 622 681 'query' => $args['query'], 623 'fields' => 'all_content_' . $locale,682 'fields' => $matching_fields, 624 683 'boost' => 0.1, 625 684 'operator' => 'and', 626 685 ), … … 629 688 array( 630 689 'multi_match' => array( 631 690 '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, 638 692 'type' => 'phrase', 639 693 'boost' => 2 640 694 ), … … 642 696 array( 643 697 'multi_match' => array( 644 698 'query' => $args['query'], 645 'fields' => array( 646 'title_' . $locale . '.ngram' 647 ), 699 'fields' => $boost_ngram_fields, 648 700 'type' => 'phrase', 649 701 'boost' => 0.2 650 702 ), … … 652 704 array( 653 705 'multi_match' => array( 654 706 'query' => $args['query'], 655 'fields' => array( 656 'title_' . $locale, 657 'slug_text', 658 ), 707 'fields' => $boost_title_fields, 659 708 'type' => 'best_fields', 660 709 'boost' => 2 661 710 ), … … 663 712 array( 664 713 'multi_match' => array( 665 714 'query' => $args['query'], 666 'fields' => array( 667 'excerpt_' . $locale, 668 'description_' . $locale, 669 'taxonomy.plugin_tags.name', 670 ), 715 'fields' => $boost_content_fields, 671 716 'type' => 'best_fields', 672 717 'boost' => 2 673 718 ),