fix(search): open tasks and list items before completed ones
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 2m36s
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 2m36s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2bb0dec744
commit
558fc46cf4
6 files changed
+38
-7
No files matched your search
@@ -273,7 +273,8 @@ func (s *Store) SearchGlobal(userID, query string) (*SearchResults, error) {
|
||||
JOIN thoughts t ON t.id = f.thought_id
|
||||
WHERE thoughts_fts MATCH ?
|
||||
AND (t.user_id = ? OR t.task_list_id IN (`+s.accessibleTaskListIDsQuery()+`))
|
||||
ORDER BY score ASC
|
||||
-- Open before completed, discarded thoughts last; within each by relevance
|
||||
ORDER BY t.status = 'discarded' ASC, t.is_completed ASC, score ASC
|
||||
LIMIT 40
|
||||
`, ftsQuery, userID, userID, userID, userID)
|
||||
if err == nil {
|
||||
@@ -330,7 +331,7 @@ func (s *Store) SearchGlobal(userID, query string) (*SearchResults, error) {
|
||||
FROM list_items_fts f
|
||||
JOIN list_items li ON li.id = f.item_id
|
||||
WHERE list_items_fts MATCH ?
|
||||
ORDER BY score ASC
|
||||
ORDER BY li.is_completed ASC, score ASC
|
||||
LIMIT 40
|
||||
`, ftsQuery)
|
||||
if err == nil {
|
||||
|
||||
@@ -212,3 +212,27 @@ func TestSearchPrefixAndSpecialCharacters(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Open tasks come before completed ones, even when a completed one matches the words better.
|
||||
func TestSearchListsOpenTasksFirst(t *testing.T) {
|
||||
store, userA, _ := setupTestStore(t)
|
||||
defer store.Close()
|
||||
|
||||
done := doneTask(t, store, userA.ID, "", "Heizung Heizung Heizung entlüften", "")
|
||||
open, _ := store.CreateThoughtWithDetails(userA.ID, "Heizung warten lassen, Termin mit dem Installateur ausmachen", "normal", "manual", "", "", "todo", "")
|
||||
_, _ = store.UpdateThoughtTriage(userA.ID, open.ID, "keep", "task", "", "", "")
|
||||
|
||||
res, err := store.SearchGlobal(userA.ID, "Heizung")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var order []string
|
||||
for _, h := range res.Hits {
|
||||
if h.Type == "thought" {
|
||||
order = append(order, h.ID)
|
||||
}
|
||||
}
|
||||
if len(order) != 2 || order[0] != open.ID || order[1] != done {
|
||||
t.Fatalf("open task should come first: %v (open %s, done %s)", order, open.ID, done)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user