Making WordPress.org

Changeset 2548


Ignore:
Timestamp:
02/22/2016 10:24:37 PM (8 years ago)
Author:
ocean90
Message:

Rosetta Roles: Use the string_score library to sort search results by match score.

See #1590.

Location:
sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/js/rosetta-roles.js

    r2544 r2548  
    8787            id: 0,
    8888            name: '',
    89             checked: false
     89            checked: false,
     90            matchScore: 0
    9091        },
    9192
     
    100101        // Search terms
    101102        terms: '',
     103
     104        _sortBy: 'checked',
    102105
    103106        initialize: function( models, options ) {
     
    151154            results = this.filter( function( project ) {
    152155                var haystack = _.union( [ project.get( 'name' ), project.get( 'slug' ) ] );
    153                 return match.test( haystack );
    154             });
    155 
     156                if ( match.test( haystack ) ) {
     157                    _.each( haystack, function( word ) {
     158                        var score = word.score( term );
     159                        project.set( 'matchScore', Math.max( score, project.get( 'matchScore' ) ) );
     160                    });
     161                    return true;
     162                }
     163                return false;
     164            });
     165
     166            this._sortBy = 'matchScore';
    156167            this.reset( results );
     168            this._sortBy = 'checked';
    157169        },
    158170
    159171        comparator: function( project ) {
    160             return - project.get( 'checked' );
     172            return - project.get( this._sortBy );
    161173        }
    162174    });
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php

    r2547 r2548  
    188188     */
    189189    public function enqueue_scripts() {
    190         wp_enqueue_script( 'rosetta-roles', plugins_url( '/js/rosetta-roles.js', __FILE__ ), array( 'jquery', 'wp-backbone' ), '6', true );
     190        wp_enqueue_script( 'string_score', plugins_url( '/js/string_score.min.js', __FILE__ ), array(), '0.1.22', true );
     191        wp_enqueue_script( 'rosetta-roles', plugins_url( '/js/rosetta-roles.js', __FILE__ ), array( 'jquery', 'wp-backbone', 'string_score' ), '6', true );
    191192    }
    192193
Note: See TracChangeset for help on using the changeset viewer.