Skip to content

Commit

Permalink
wip prioritize prefix among popular
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Dec 7, 2024
1 parent 5a88224 commit fcc5f06
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions lib/model/emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -374,22 +374,38 @@ class EmojiAutocompleteView extends AutocompleteView<EmojiAutocompleteQuery, Emo
return match == null ? null : EmojiAutocompleteResult(match, candidate);
}

static const _numResultRanks = 6;

static const _numResultRanks = 7;

// Compare sort_emojis in Zulip web:shared/src/typeahead.ts .
// Differences in behavior include:
// * Web ranks each name of a Unicode emoji separately.
// * Among popular emoji with non-exact matches,
// web doesn't prioritize by quality of match; we do.
// * OTOH web only counts an emoji as "popular" for ranking if the query
// is a prefix of a word in the emoji's name or alias.
// TODO reconcile that; requiring word boundary may be helpful;
// rejecting query that spans words seems unhelpful.
// * TODO web ranks matches starting at a word boundary ahead of other
// non-prefix matches; we don't yet.
// * Web distinguishes prefix matches by case-sensitive vs. not; we don't.
// That doesn't seem helpful for emoji search.
// * Web suppresses Unicode emoji names shadowed by a realm emoji
// only if the latter is also a match for the query. That mostly works,
// because emoji with the same name will mostly both match or both not;
// but it breaks if the Unicode emoji was a literal match.
// TODO(web): that's a bug
static int _rankResult(EmojiAutocompleteResult result) {
if (result.matchQuality == EmojiMatchQuality.exact) {
return 0;
}
final candidate = result.candidate;
if (_isPopularEmoji(candidate)) {
return 1;
}
final isPopular = _isPopularEmoji(candidate);
final isRealmEmoji = (candidate.emojiType == ReactionType.realmEmoji);
return switch (result.matchQuality) {
EmojiMatchQuality.exact => throw Error(), // handled above
EmojiMatchQuality.prefix => isRealmEmoji ? 2 : 3,
EmojiMatchQuality.prefix => isPopular ? 1 : isRealmEmoji ? 3 : 4,
// TODO word-boundary vs. not
EmojiMatchQuality.internal => isRealmEmoji ? 4 : 5,
EmojiMatchQuality.internal => isPopular ? 2 : isRealmEmoji ? 5 : 6,
};
}

Expand Down

0 comments on commit fcc5f06

Please sign in to comment.