WordPress.org

Making WordPress.org

Changeset 3550


Ignore:
Timestamp:
06/22/2016 02:49:08 PM (2 years 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

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-query-plugins.php

    r3501 r3550  
    1919        'plugin_category',
    2020        's',
    21         'author_name'
     21        'author_name',
     22        'installed_plugins'
    2223    );
    2324
  • 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' );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api-request.php

    r3289 r3550  
    153153        if ( ! empty( $this->args->browse ) ) {
    154154            $query['browse'] = $this->args->browse;
     155            if ( !empty( $this->args->installed_plugins ) )
     156                $query['installed_plugins'] = is_array( $this->args->installed_plugins ) ? $this->args->installed_plugins : array();
    155157
    156158        } elseif ( ! empty( $this->args->user ) ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api.php

    r3496 r3550  
    143143        $cache_key = $this->query_plugins_cache_key( $request );
    144144
    145         if ( false === ( $response = wp_cache_get( $cache_key, self::CACHE_GROUP ) ) ) {
     145        if ( true || false === ( $response = wp_cache_get( $cache_key, self::CACHE_GROUP ) ) ) {
    146146            $response = $this->internal_rest_api_call( 'plugins/v1/query-plugins', $request->query_plugins_params_for_query() );
    147147            if ( 200 != $response->status ) {
Note: See TracChangeset for help on using the changeset viewer.