Bug 325458 - Recipient Autocomplete: Nickname should get highest precedence for matching address book entries; r=mkmelin

This commit is contained in:
Suyash Agarwal 2015-02-04 20:56:01 +13:00
Родитель 208779c49c
Коммит 5d10cc7c7d
3 изменённых файлов: 40 добавлений и 10 удалений

Просмотреть файл

@ -129,17 +129,27 @@ nsAbAutoCompleteSearch.prototype = {
* results that match the beginning of a "word" in the result to score better
* than a result that matches only in the middle of the word.
*
* @param aCard - the card whose score is being decided
* @param aAddress - full lower-cased address, including display name and address
* @param aSearchString - search string provided by user
* @return a score; a higher score is better than a lower one
*/
_getScore: function(aAddress, aSearchString) {
_getScore: function(aCard, aAddress, aSearchString) {
const BEST = 100;
// We will firstly check if the search term provided by the user
// is the nick name for the card or at least in the beginning of it.
let nick = aCard.getProperty("NickName", "").toLocaleLowerCase();
aSearchString = aSearchString.toLocaleLowerCase();
if (nick == aSearchString)
return BEST + 1;
if (nick.indexOf(aSearchString) == 0)
return BEST;
// We'll do this case-insensitively and ignore the domain.
let atIdx = aAddress.lastIndexOf("@");
if (atIdx != -1) // mail lists don't have an @
aAddress = aAddress.substr(0, atIdx);
aSearchString = aSearchString.toLocaleLowerCase();
let idx = aAddress.indexOf(aSearchString);
if (idx == 0)
return BEST;
@ -296,7 +306,7 @@ nsAbAutoCompleteSearch.prototype = {
isPrimaryEmail: isPrimaryEmail,
emailToUse: emailToUse,
popularity: this._getPopularityIndex(directory, card),
score: this._getScore(lcEmailAddress, result.searchString)
score: this._getScore(card, lcEmailAddress, result.searchString)
});
},

Просмотреть файл

@ -46,11 +46,11 @@ const displayNames = [ { search: "d", expected: [5, 0, 1, 2, 3, 4, 9] },
{ search: "displ", expected: [5, 4]},
{ search: "displa", expected: [5]} ];
const nickNames = [ { search: "n", expected: [5, 0, 1, 2, 3, 4] },
{ search: "ni", expected: [5, 0, 1, 2, 3] },
{ search: "nic", expected: [5, 1, 2, 3] },
{ search: "nick", expected: [5, 2, 3] },
{ search: "nickn", expected: [5, 3] },
const nickNames = [ { search: "n", expected: [4, 5, 0, 1, 2, 3] },
{ search: "ni", expected: [0, 5, 1, 2, 3] },
{ search: "nic", expected: [1, 5, 2, 3] },
{ search: "nick", expected: [2, 5, 3] },
{ search: "nickn", expected: [3, 5] },
{ search: "nickna", expected: [5] } ];
const emails = [ { search: "e", expected: [0, 1, 2, 3, 4, 5, 7, 8, 9] },

Просмотреть файл

@ -77,6 +77,23 @@ const cards = [
email: "13@example.com", displayName: "mr iron man (exp dev)",
popularityIndex: 0, firstName: "iron", lastName: "man",
value: "mr iron man (exp dev) <13@example.com>"
},
{ // 14
email: "14@example.com", displayName: "michael",
popularityIndex: 0, nickName: "short",
value: "michael <14@example.com>"
},
{ // 15
email: "15@example.com", displayName: "good boy",
popularityIndex: 0, nickName: "sh",
value: "good boy <15@example.com>"
},
{ // 16
email: "16@example.com", displayName: "sherlock holmes",
popularityIndex: 0, value: "sherlock holmes <16@example.com>"
}
];
@ -87,11 +104,13 @@ const inputs = [
{ search: "who", expected: [1, 0, 6] },
{ search: "xx", expected: [0, 5] },
{ search: "jan", expected: [1, 3] },
{ search: "sh", expected: [2, 10, 7] },
// expecting nickname to score highest.
{ search: "sh", expected: [15, 14, 16, 2, 10, 7] },
{ search: "st", expected: [3,8] },
{ search: "paul mary", expected: [11, 12] },
{ search: "\"paul mary\"", expected: [11] },
{ search: "\"iron man\" mr \"exp dev\"", expected: [13] }
{ search: "\"iron man\" mr \"exp dev\"", expected: [13] },
{ search: "short", expected: [14] }
];
function acObserver() {}
@ -125,6 +144,7 @@ function run_test()
card.setProperty("PopularityIndex", element.popularityIndex);
card.firstName = element.firstName;
card.lastName = element.lastName;
card.setProperty("NickName", element.nickName);
ab.addCard(card);
}