feat: harden search ranking and deduplication
This commit is contained in:
@@ -20,3 +20,19 @@ func TestSearchContactsFromMessagesMatchesBareJIDs(t *testing.T) {
|
||||
t.Fatalf("SearchContactsFromMessages() = %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchContactsRanksExactAndDeduplicates(t *testing.T) {
|
||||
messages := []Message{
|
||||
{ID: "msg-1", SenderID: "zzz-target@imopenfire1-lanzhou", ReceiverID: "target@imopenfire1-lanzhou"},
|
||||
{ID: "msg-2", SenderID: "TARGET@imopenfire1-lanzhou", ReceiverID: "other@imopenfire1-lanzhou"},
|
||||
}
|
||||
|
||||
got := SearchContactsFromMessages(messages, SearchContactsQuery{Query: "target@imopenfire1-lanzhou", Limit: 10})
|
||||
want := SearchContactsResult{Contacts: []Contact{
|
||||
{ContactID: "target@imopenfire1-lanzhou", DisplayName: "target@imopenfire1-lanzhou", Account: "target@imopenfire1-lanzhou", Source: "local_readonly", Confidence: 0.6, RawRef: "message_jid"},
|
||||
{ContactID: "zzz-target@imopenfire1-lanzhou", DisplayName: "zzz-target@imopenfire1-lanzhou", Account: "zzz-target@imopenfire1-lanzhou", Source: "local_readonly", Confidence: 0.6, RawRef: "message_jid"},
|
||||
}}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("SearchContactsFromMessages() = %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user