Search: order results newest first in every group
Chat hits sort by the chat's last use whatever field matched, and run, step, field, artifact and pipeline hits sort by their own date, before the result cap applies so the cap drops the oldest. Each kind's row scan also walks newest first. Score still reports the match tier. The app sorts both groups newest first as well.
This commit is contained in:
@@ -21,8 +21,8 @@ var chatSearchBudget = time.Second
|
||||
// chatSearchConcurrency is how many transcripts one chat search reads at once.
|
||||
const chatSearchConcurrency = 4
|
||||
|
||||
// Chat hit scores: a title match outranks a directory match, which outranks a
|
||||
// message-text match; recency breaks ties.
|
||||
// Chat hit scores record how a chat matched: title, directory or message
|
||||
// text. They describe the hit; results are ordered by recency alone.
|
||||
const (
|
||||
chatScoreTitleExact = 4
|
||||
chatScoreTitle = 3
|
||||
@@ -55,7 +55,8 @@ func chatSearchReply(ctx context.Context, request protocol.Message, broker chatB
|
||||
// SearchChatMessagesPerChat messages of up to SearchMaxScanChats of the most
|
||||
// recently used sessions the registry did not already match, read through the
|
||||
// chat broker concurrently within chatSearchBudget. One session yields at most
|
||||
// one hit, its best match. A blank query lists the most recent chats.
|
||||
// one hit, its best match. Hits are ordered most recently used first before
|
||||
// the cap applies. A blank query lists the most recent chats.
|
||||
func searchChats(ctx context.Context, req protocol.SearchRequest, broker chatBroker, registry operatorRegistry) (*protocol.SearchResponse, error) {
|
||||
query := strings.TrimSpace(req.Query)
|
||||
response := &protocol.SearchResponse{
|
||||
@@ -98,16 +99,7 @@ func searchChats(ctx context.Context, req protocol.SearchRequest, broker chatBro
|
||||
response.Truncated = true
|
||||
}
|
||||
}
|
||||
sort.SliceStable(results, func(i, j int) bool {
|
||||
a, b := results[i], results[j]
|
||||
if a.Score != b.Score {
|
||||
return a.Score > b.Score
|
||||
}
|
||||
if a.Recency != b.Recency {
|
||||
return a.Recency > b.Recency
|
||||
}
|
||||
return a.Target < b.Target
|
||||
})
|
||||
sortChatSearchResults(results)
|
||||
if len(results) > response.Cap {
|
||||
results = results[:response.Cap]
|
||||
response.Truncated = true
|
||||
@@ -118,6 +110,18 @@ func searchChats(ctx context.Context, req protocol.SearchRequest, broker chatBro
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// sortChatSearchResults orders chat hits most recently used first, whatever
|
||||
// field matched, so the cap keeps the newest chats. Session id breaks ties.
|
||||
func sortChatSearchResults(results []protocol.SearchResult) {
|
||||
sort.SliceStable(results, func(i, j int) bool {
|
||||
a, b := results[i].Chat.UpdatedAt, results[j].Chat.UpdatedAt
|
||||
if a != b {
|
||||
return a > b
|
||||
}
|
||||
return results[i].Target < results[j].Target
|
||||
})
|
||||
}
|
||||
|
||||
// chatSearchLimit clamps a requested cap like the store's search does.
|
||||
func chatSearchLimit(limit int) int {
|
||||
if limit <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user