Ticket #1692: precision-matching.diff
File precision-matching.diff, 3.9 KB (added by , 4 years ago) |
---|
-
wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php
283 283 } 284 284 } 285 285 286 $locale = get_locale(); 287 if ( $locale && $locale !== 'en' && $locale !== 'en_US' ) { 288 $es_wp_query_args['query_fields'] = array( "title_{$locale}^1.2", 'title_en^0.2', "content_{$locale}", 'content_en^0.2', "excerpt_{$locale}^1.2", 'excerpt_en^0.2', 'author', 'tag', 'category', 'slug_ngram^0.005', 'slug^1.2', 'contributors' ); 289 } else { 290 $es_wp_query_args['query_fields'] = array( 'title_en^1.2', 'content_en', 'excerpt_en^1.2', 'author', 'tag', 'category', 'slug_ngram^0.005', 'slug^1.2', 'contributors' ); 291 } 292 286 $es_wp_query_args['locale'] = get_locale(); 287 293 288 // You can use this filter to modify the search query parameters, such as controlling the post_type. 294 289 // These arguments are in the format for convert_wp_es_to_es_args(), i.e. WP-style. 295 290 $es_wp_query_args = apply_filters( 'jetpack_search_es_wp_query_args', $es_wp_query_args, $query ); … … 487 482 'blog_id' => get_current_blog_id(), 488 483 489 484 'query' => null, // Search phrase 490 'query_fields' => array( 'title_en^2', 'content_en', 'author', 'tag', 'category', 'slug_ngram', 'contributors' ), 485 'query_fields' => array(), // hacking to be able to do a very different type of query 486 'locale' => false, 491 487 492 488 'post_type' => null, // string or an array 493 489 'terms' => array(), // ex: array( 'taxonomy-1' => array( 'slug' ), 'taxonomy-2' => array( 'slug-a', 'slug-b' ) ) … … 606 602 } 607 603 } 608 604 605 if ( $args['locale'] && $args['locale'] !== 'en' && $args['locale'] !== 'en_US' ) { 606 $locale = $args['locale']; 607 } else { 608 $locale = 'en'; 609 } 610 609 611 /////////////////////////////////////////////////////////// 610 612 // Build the query - potentially extracting more filters 611 613 // TODO: add auto phrase searching … … 618 620 'must' => array( 619 621 'multi_match' => array( 620 622 'query' => $args['query'], 621 'fields' => $args['query_fields'],622 ' type' => 'cross_fields',623 'fields' => 'all_content_' . $locale, 624 'boost' => 0.1, 623 625 'operator' => 'and', 624 626 ), 625 627 ), … … 627 629 array( 628 630 'multi_match' => array( 629 631 'query' => $args['query'], 630 'fields' => $args['query_fields'], 632 'fields' => array( 633 'title_' . $locale, 634 'excerpt_' . $locale, 635 'description_' . $locale, 636 'taxonomy.plugin_tags.name', 637 ), 631 638 'type' => 'phrase', 639 'boost' => 2 632 640 ), 633 641 ), 642 array( 643 'multi_match' => array( 644 'query' => $args['query'], 645 'fields' => array( 646 'title_' . $locale . '.ngram' 647 ), 648 'type' => 'phrase', 649 'boost' => 0.2 650 ), 651 ), 652 array( 653 'multi_match' => array( 654 'query' => $args['query'], 655 'fields' => array( 656 'title_' . $locale, 657 'slug_text', 658 ), 659 'type' => 'best_fields', 660 'boost' => 2 661 ), 662 ), 663 array( 664 'multi_match' => array( 665 'query' => $args['query'], 666 'fields' => array( 667 'excerpt_' . $locale, 668 'description_' . $locale, 669 'taxonomy.plugin_tags.name', 670 ), 671 'type' => 'best_fields', 672 'boost' => 2 673 ), 674 ), 675 array( 676 'multi_match' => array( 677 'query' => $args['query'], 678 'fields' => array( 679 'author', 680 'contributors', 681 ), 682 'type' => 'best_fields', 683 'boost' => 2 684 ), 685 ), 634 686 ), 635 687 ), 636 688 ); … … 794 846 ), 795 847 ), 796 848 'boost_mode' => 'multiply', 797 'max_boost' => 5,798 849 ) 799 850 ), 800 851 )