WordPress.org

Making WordPress.org


Ignore:
Timestamp:
06/22/16 14:49:08 (18 months ago)
Author:
tellyworth
Message:

Plugin directory: implement a simple recommended plugins API response using Elasticsearch.

This returns a list of plugins with the following criteria:

  • Not already installed
  • Tested-up-to is close to the requesting site's WP version
  • Scoring accounts for similar factors as a regular search

See #1729

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php

    r3542 r3550  
    248248 
    249249        // ES API does not allow more than 15 results at a time 
    250         if ( $posts_per_page > 15 ) 
    251             $posts_per_page = 15; 
     250        if ( $posts_per_page > 200 ) 
     251            $posts_per_page = 200; 
    252252 
    253253        $date_cutoff = strftime( '%Y-%m-%d', strtotime( '-2 years' ) ); 
    254254        $date_today = strftime( '%Y-%m-%d' ); 
    255255        $version_cutoff = ( defined('WP_CORE_STABLE_BRANCH') ? sprintf( '%0.1f', WP_CORE_STABLE_BRANCH - 0.5) : '4.0' ); 
     256 
     257        // If the request comes from WordPress and the major version string looks sane, use a more specific version constraint 
     258        if ( preg_match( '|WordPress/(\d+[.]\d+)|', $_SERVER['HTTP_USER_AGENT'], $matches ) ) { 
     259            if ( $matches[1] >= $version_cutoff && $matches[1] <= WP_CORE_STABLE_BRANCH ) { 
     260                $version_cutoff = sprintf( '%0.1f', $matches[1] - 0.2 ); 
     261            } 
     262        } 
    256263 
    257264        // Start building the WP-style search query args 
     
    272279        ); 
    273280 
     281        if ( defined( 'WPORG_IS_API' ) && WPORG_IS_API ) { 
     282            // Look for plugins excluding those already installed 
     283            if ( isset( $query->query['installed_plugins'] ) ) { 
     284                $es_wp_query_args['filters'][] = array( 'not' => array( 'terms' => array( 'slug' => $query->query['installed_plugins'] ) ) ); 
     285            } 
     286        } 
     287         
    274288        $locale = get_locale(); 
    275289        if ( $locale && $locale !== 'en' && $locale !== 'en_US' ) { 
     
    327341 
    328342    public function action__pre_get_posts( $query ) { 
     343        // Treat an API request for the recommended tab as a search, even though there is no search string in the query 
     344        if ( defined( 'WPORG_IS_API' ) && WPORG_IS_API && isset( $query->query['browse'] ) && $query->query['browse'] === 'recommended' ) 
     345            $query->is_search = true; 
     346 
    329347        if ( ! $query->is_main_query() || ! $query->is_search() ) 
    330348            return; 
     
    610628            } 
    611629        } else { 
     630            $query = array( 'match_all' => array() ); 
     631            $es_query_args['query'] = Jetpack_Search::score_query_by_recency( $query ); 
    612632            if ( ! $args['orderby'] ) { 
    613633                $args['orderby'] = array( 'date' ); 
Note: See TracChangeset for help on using the changeset viewer.