@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve ordering of main typeahead results

Summary:
Always order applications first, then users, then other results (currently, there are no other results, of course).

(This is similar to the general ordering algorithm used in JX.Prefab but has enough current/future differences that I split it rather than trying to share them.)

Test Plan: Queried results, verified order.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1569

Differential Revision: https://secure.phabricator.com/D3117

+57 -6
+3 -2
src/__celerity_resource_map__.php
··· 1462 1462 ), 1463 1463 'javelin-behavior-phabricator-search-typeahead' => 1464 1464 array( 1465 - 'uri' => '/res/9ceffb09/rsrc/js/application/core/behavior-search-typeahead.js', 1465 + 'uri' => '/res/f552b264/rsrc/js/application/core/behavior-search-typeahead.js', 1466 1466 'type' => 'js', 1467 1467 'requires' => 1468 1468 array( ··· 1471 1471 2 => 'javelin-typeahead', 1472 1472 3 => 'javelin-dom', 1473 1473 4 => 'javelin-uri', 1474 - 5 => 'javelin-stratcom', 1474 + 5 => 'javelin-util', 1475 + 6 => 'javelin-stratcom', 1475 1476 ), 1476 1477 'disk' => '/rsrc/js/application/core/behavior-search-typeahead.js', 1477 1478 ),
+54 -4
webroot/rsrc/js/application/core/behavior-search-typeahead.js
··· 5 5 * javelin-typeahead 6 6 * javelin-dom 7 7 * javelin-uri 8 + * javelin-util 8 9 * javelin-stratcom 9 10 */ 10 11 ··· 30 31 ]); 31 32 32 33 return { 33 - name : object[0], 34 - display : render, 35 - uri : object[1], 36 - id : object[2] 34 + name: object[0], 35 + display: render, 36 + uri: object[1], 37 + id: object[2], 38 + priority: object[3], 39 + type: object[7] 37 40 }; 38 41 } 39 42 40 43 datasource.setTransformer(transform); 44 + 45 + // Sort handler that orders results by type (e.g., applications, users) 46 + // and then selects for good matches on the "priority" substrings if they 47 + // exist (for instance, username matches are preferred over real name 48 + // matches, and application name matches are preferred over application 49 + // flavor text matches). 50 + 51 + var sort_handler = function(value, list, cmp) { 52 + var priority_hits = {}; 53 + var type_priority = { 54 + // TODO: Put jump nav hits like "D123" first. 55 + 'apps' : 2, 56 + 'user' : 3 57 + }; 58 + 59 + var tokens = this.tokenize(value); 60 + 61 + for (var ii = 0; ii < list.length; ii++) { 62 + var item = list[ii]; 63 + if (!item.priority) { 64 + continue; 65 + } 66 + 67 + for (var jj = 0; jj < tokens.length; jj++) { 68 + if (item.priority.substr(0, tokens[jj].length) == tokens[jj]) { 69 + priority_hits[item.id] = true; 70 + } 71 + } 72 + } 73 + 74 + list.sort(function(u, v) { 75 + var u_type = type_priority[u.type] || 999; 76 + var v_type = type_priority[v.type] || 999; 77 + 78 + if (u_type != v_type) { 79 + return u_type - v_type; 80 + } 81 + 82 + if (priority_hits[u.id] != priority_hits[v.id]) { 83 + return priority_hits[v.id] ? 1 : -1; 84 + } 85 + 86 + return cmp(u, v); 87 + }); 88 + }; 89 + 90 + datasource.setSortHandler(JX.bind(datasource, sort_handler)); 41 91 42 92 var typeahead = new JX.Typeahead(JX.$(config.id), JX.$(config.input)); 43 93 typeahead.setDatasource(datasource);