Changeset 4173
- Timestamp:
- 09/30/2016 10:16:13 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php
r3597 r4173 1 <?php 1 <?php 2 2 /* 3 3 * WARNING: This file is distributed verbatim in Jetpack. … … 11 11 * This is a preliminary version of Jetpack Search. 12 12 * It is highly likely that 95% of the time the search will not be using the loop. 13 * 13 * 14 14 */ 15 15 … … 278 278 } 279 279 } 280 280 281 281 $locale = get_locale(); 282 282 if ( $locale && $locale !== 'en' && $locale !== 'en_US' ) { … … 294 294 295 295 //Only trust ES to give us IDs, not the content since it is a mirror 296 $es_query_args['fields'] = array( 296 $es_query_args['fields'] = array( 297 297 'post_id', 298 298 'blog_id' … … 313 313 $this->found_posts = $this->search_result['results']['total']; 314 314 315 // Don't select anything, posts are inflated by Jetpack_SearchResult_Posts_Iterator 315 // Don't select anything, posts are inflated by Jetpack_SearchResult_Posts_Iterator 316 316 // in The Loop, to allow for multi site search 317 317 return ''; … … 466 466 $defaults = array( 467 467 'blog_id' => get_current_blog_id(), 468 468 469 469 'query' => null, // Search phrase 470 470 'query_fields' => array( 'title_en^2', 'content_en', 'author', 'tag', 'category', 'slug_ngram', 'contributors' ), 471 471 472 472 'post_type' => null, // string or an array 473 473 'terms' => array(), // ex: array( 'taxonomy-1' => array( 'slug' ), 'taxonomy-2' => array( 'slug-a', 'slug-b' ) ) 474 474 475 475 'author' => null, // id or an array of ids 476 476 'author_name' => array(), // string or an array 477 477 478 478 'date_range' => null, // array( 'field' => 'date', 'gt' => 'YYYY-MM-dd', 'lte' => 'YYYY-MM-dd' ); date formats: 'YYYY-MM-dd' or 'YYYY-MM-dd HH:MM:SS' 479 479 'tested_range' => null, 480 480 'filters' => array(), 481 481 482 482 'orderby' => null, // Defaults to 'relevance' if query is set, otherwise 'date'. Pass an array for multiple orders. 483 483 'order' => 'DESC', 484 484 485 485 'posts_per_page' => 10, 486 486 'offset' => null, 487 487 'paged' => null, 488 488 489 489 /** 490 490 * Facets. Examples: … … 496 496 'facets' => null, 497 497 ); 498 498 499 499 $raw_args = $args; // Keep a copy 500 500 501 501 $args = wp_parse_args( $args, $defaults ); 502 502 503 503 $es_query_args = array( 504 504 'blog_id' => absint( $args['blog_id'] ), … … 507 507 508 508 //TODO: limit size to 15 509 509 510 510 // ES "from" arg (offset) 511 511 if ( $args['offset'] ) { … … 514 514 $es_query_args['from'] = max( 0, ( absint( $args['paged'] ) - 1 ) * $es_query_args['size'] ); 515 515 } 516 516 517 517 if ( !is_array( $args['author_name'] ) ) { 518 518 $args['author_name'] = array( $args['author_name'] ); 519 519 } 520 520 521 521 // ES stores usernames, not IDs, so transform 522 522 if ( ! empty( $args['author'] ) ) { … … 525 525 foreach ( $args['author'] as $author ) { 526 526 $user = get_user_by( 'id', $author ); 527 527 528 528 if ( $user && ! empty( $user->user_login ) ) { 529 529 $args['author_name'][] = $user->user_login; … … 538 538 // May get performance boost by also caching the top level boolean filter too. 539 539 $filters = array(); 540 540 541 541 if ( $args['post_type'] ) { 542 542 if ( !is_array( $args['post_type'] ) ) … … 544 544 $filters[] = array( 'terms' => array( 'post_type' => $args['post_type'] ) ); 545 545 } 546 546 547 547 if ( $args['author_name'] ) { 548 548 $filters[] = array( 'terms' => array( 'author_login' => $args['author_name'] ) ); 549 549 } 550 550 551 551 if ( !empty( $args['date_range'] ) && isset( $args['date_range']['field'] ) ) { 552 552 $field = $args['date_range']['field']; … … 564 564 $filters = array_merge( $filters, $args['filters'] ); 565 565 } 566 566 567 567 if ( is_array( $args['terms'] ) ) { 568 568 foreach ( $args['terms'] as $tax => $terms ) { … … 594 594 if ( $args['query'] ) { 595 595 $analyzer = Jetpack_Search::get_analyzer_name( $this->blog_lang ); 596 $query = array( 596 $query = array( 597 597 'bool' => array( 598 598 'must' => array( … … 629 629 } 630 630 } 631 631 632 632 // Validate the "order" field 633 633 switch ( strtolower( $args['order'] ) ) { … … 640 640 break; 641 641 } 642 642 643 643 $es_query_args['sort'] = array(); 644 644 foreach ( (array) $args['orderby'] as $orderby ) { … … 664 664 unset( $es_query_args['sort'] ); 665 665 666 666 667 667 if ( ! empty( $filters ) ) { 668 668 $es_query_args['filter'] = array( 'and' => $filters ); … … 714 714 $date_origin = date( 'Y-m-d' ); 715 715 716 return array( 716 return array( 717 717 'filtered' => array( 718 718 'query' => array(
Note: See TracChangeset
for help on using the changeset viewer.