1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

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
This commit is contained in:
epriestley 2012-08-01 12:36:33 -07:00
parent 7be02e659a
commit bc46e953f7
2 changed files with 57 additions and 6 deletions

View file

@ -1462,7 +1462,7 @@ celerity_register_resource_map(array(
),
'javelin-behavior-phabricator-search-typeahead' =>
array(
'uri' => '/res/9ceffb09/rsrc/js/application/core/behavior-search-typeahead.js',
'uri' => '/res/f552b264/rsrc/js/application/core/behavior-search-typeahead.js',
'type' => 'js',
'requires' =>
array(
@ -1471,7 +1471,8 @@ celerity_register_resource_map(array(
2 => 'javelin-typeahead',
3 => 'javelin-dom',
4 => 'javelin-uri',
5 => 'javelin-stratcom',
5 => 'javelin-util',
6 => 'javelin-stratcom',
),
'disk' => '/rsrc/js/application/core/behavior-search-typeahead.js',
),

View file

@ -5,6 +5,7 @@
* javelin-typeahead
* javelin-dom
* javelin-uri
* javelin-util
* javelin-stratcom
*/
@ -30,15 +31,64 @@ JX.behavior('phabricator-search-typeahead', function(config) {
]);
return {
name : object[0],
display : render,
uri : object[1],
id : object[2]
name: object[0],
display: render,
uri: object[1],
id: object[2],
priority: object[3],
type: object[7]
};
}
datasource.setTransformer(transform);
// Sort handler that orders results by type (e.g., applications, users)
// and then selects for good matches on the "priority" substrings if they
// exist (for instance, username matches are preferred over real name
// matches, and application name matches are preferred over application
// flavor text matches).
var sort_handler = function(value, list, cmp) {
var priority_hits = {};
var type_priority = {
// TODO: Put jump nav hits like "D123" first.
'apps' : 2,
'user' : 3
};
var tokens = this.tokenize(value);
for (var ii = 0; ii < list.length; ii++) {
var item = list[ii];
if (!item.priority) {
continue;
}
for (var jj = 0; jj < tokens.length; jj++) {
if (item.priority.substr(0, tokens[jj].length) == tokens[jj]) {
priority_hits[item.id] = true;
}
}
}
list.sort(function(u, v) {
var u_type = type_priority[u.type] || 999;
var v_type = type_priority[v.type] || 999;
if (u_type != v_type) {
return u_type - v_type;
}
if (priority_hits[u.id] != priority_hits[v.id]) {
return priority_hits[v.id] ? 1 : -1;
}
return cmp(u, v);
});
};
datasource.setSortHandler(JX.bind(datasource, sort_handler));
var typeahead = new JX.Typeahead(JX.$(config.id), JX.$(config.input));
typeahead.setDatasource(datasource);
typeahead.setPlaceholder(config.placeholder);