Skip to content

Commit

Permalink
fix scoring for inbox name search (keybase#24412)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblum authored Jan 6, 2021
1 parent a144e0c commit 7e134de
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions go/chat/inboxsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,12 +1120,30 @@ func (h convSearchHit) score(emptyMode types.InboxSourceSearchEmptyMode) (score
default:
htime = utils.GetConvMtime(h.conv)
}

lastActiveScore := opensearch.NormalizeLastActive(lastActiveMinHours, lastActiveMaxHours, keybase1.Time(htime))
return score + lastActiveScore*lastActiveWeight
score += lastActiveScore * lastActiveWeight
return score
}

func (h convSearchHit) less(o convSearchHit, emptyMode types.InboxSourceSearchEmptyMode) bool {
return h.score(emptyMode) <= o.score(emptyMode)
hScore := h.score(emptyMode)
oScore := o.score(emptyMode)
if hScore < oScore {
return true
} else if hScore > oScore {
return false
}
var htime, otime gregor1.Time
switch emptyMode {
case types.InboxSourceSearchEmptyModeAllBySendCtime:
htime = utils.GetConvLastSendTime(h.conv)
otime = utils.GetConvLastSendTime(o.conv)
default:
htime = utils.GetConvMtime(h.conv)
otime = utils.GetConvMtime(o.conv)
}
return htime.Before(otime)
}

func (h convSearchHit) valid() bool {
Expand Down Expand Up @@ -1243,6 +1261,7 @@ func (s *HybridInboxSource) Search(ctx context.Context, uid gregor1.UID, query s
}
hits = append(hits, hit)
}

sort.Slice(hits, func(i, j int) bool {
return hits[j].less(hits[i], emptyMode)
})
Expand Down

0 comments on commit 7e134de

Please sign in to comment.