Making WordPress.org

Changeset 4173


Ignore:
Timestamp:
09/30/2016 10:16:13 AM (8 years ago)
Author:
ocean90
Message:

Plugin Directory: Whitespace cleanup for Jetpack_Search.

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
    22/*
    33 * WARNING: This file is distributed verbatim in Jetpack.
     
    1111 * This is a preliminary version of Jetpack Search.
    1212 * It is highly likely that 95% of the time the search will not be using the loop.
    13  * 
     13 *
    1414 */
    1515
     
    278278            }
    279279        }
    280        
     280
    281281        $locale = get_locale();
    282282        if ( $locale && $locale !== 'en' && $locale !== 'en_US' ) {
     
    294294
    295295        //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(
    297297            'post_id',
    298298            'blog_id'
     
    313313        $this->found_posts = $this->search_result['results']['total'];
    314314
    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
    316316        // in The Loop, to allow for multi site search
    317317        return '';
     
    466466        $defaults = array(
    467467            'blog_id'        => get_current_blog_id(),
    468    
     468
    469469            'query'          => null,    // Search phrase
    470470            'query_fields'   => array( 'title_en^2', 'content_en', 'author', 'tag', 'category', 'slug_ngram', 'contributors' ),
    471    
     471
    472472            'post_type'      => null,  // string or an array
    473473            'terms'          => array(), // ex: array( 'taxonomy-1' => array( 'slug' ), 'taxonomy-2' => array( 'slug-a', 'slug-b' ) )
    474    
     474
    475475            'author'         => null,    // id or an array of ids
    476476            'author_name'    => array(), // string or an array
    477    
     477
    478478            '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'
    479479            'tested_range'   => null,
    480480            'filters'        => array(),
    481    
     481
    482482            'orderby'        => null,    // Defaults to 'relevance' if query is set, otherwise 'date'. Pass an array for multiple orders.
    483483            'order'          => 'DESC',
    484    
     484
    485485            'posts_per_page' => 10,
    486486            'offset'         => null,
    487487            'paged'          => null,
    488    
     488
    489489            /**
    490490             * Facets. Examples:
     
    496496            'facets'         => null,
    497497        );
    498    
     498
    499499        $raw_args = $args; // Keep a copy
    500    
     500
    501501        $args = wp_parse_args( $args, $defaults );
    502    
     502
    503503        $es_query_args = array(
    504504            'blog_id' => absint( $args['blog_id'] ),
     
    507507
    508508        //TODO: limit size to 15
    509    
     509
    510510        // ES "from" arg (offset)
    511511        if ( $args['offset'] ) {
     
    514514            $es_query_args['from'] = max( 0, ( absint( $args['paged'] ) - 1 ) * $es_query_args['size'] );
    515515        }
    516    
     516
    517517        if ( !is_array( $args['author_name'] ) ) {
    518518            $args['author_name'] = array( $args['author_name'] );
    519519        }
    520    
     520
    521521        // ES stores usernames, not IDs, so transform
    522522        if ( ! empty( $args['author'] ) ) {
     
    525525            foreach ( $args['author'] as $author ) {
    526526                $user = get_user_by( 'id', $author );
    527    
     527
    528528                if ( $user && ! empty( $user->user_login ) ) {
    529529                    $args['author_name'][] = $user->user_login;
     
    538538        // May get performance boost by also caching the top level boolean filter too.
    539539        $filters = array();
    540    
     540
    541541        if ( $args['post_type'] ) {
    542542            if ( !is_array( $args['post_type'] ) )
     
    544544            $filters[] = array( 'terms' => array( 'post_type' => $args['post_type'] ) );
    545545        }
    546    
     546
    547547        if ( $args['author_name'] ) {
    548548            $filters[] = array( 'terms' => array( 'author_login' => $args['author_name'] ) );
    549549        }
    550    
     550
    551551        if ( !empty( $args['date_range'] ) && isset( $args['date_range']['field'] ) ) {
    552552            $field = $args['date_range']['field'];
     
    564564            $filters = array_merge( $filters, $args['filters'] );
    565565        }
    566    
     566
    567567        if ( is_array( $args['terms'] ) ) {
    568568            foreach ( $args['terms'] as $tax => $terms ) {
     
    594594        if ( $args['query'] ) {
    595595            $analyzer = Jetpack_Search::get_analyzer_name( $this->blog_lang );
    596             $query = array( 
     596            $query = array(
    597597                'bool' => array(
    598598                    'must' => array(
     
    629629            }
    630630        }
    631    
     631
    632632        // Validate the "order" field
    633633        switch ( strtolower( $args['order'] ) ) {
     
    640640                break;
    641641        }
    642    
     642
    643643        $es_query_args['sort'] = array();
    644644        foreach ( (array) $args['orderby'] as $orderby ) {
     
    664664            unset( $es_query_args['sort'] );
    665665
    666    
     666
    667667        if ( ! empty( $filters ) ) {
    668668            $es_query_args['filter'] = array( 'and' => $filters );
     
    714714        $date_origin = date( 'Y-m-d' );
    715715
    716         return array( 
     716        return array(
    717717            'filtered' => array(
    718718                'query' => array(
Note: See TracChangeset for help on using the changeset viewer.