From 73d27f0327854470965dfcd8ec2b840fd6965591 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Tue, 21 Nov 2023 11:38:51 -0500 Subject: [PATCH] Sort search by default group sort (#29) --- CHANGELOG.md | 14 ++++++++------ client/search.coffee | 16 +++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72504618..8482167c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,14 @@ instead of version numbers. * Only cluster by leading tags in the sort order, so if you click to sort by e.g. Updated then there's no longer awkward clustering by repeated tags. -* Search no longer supports quoting phrases with single quotes, so that it's - easier to search for possessives (e.g. `Erik's`). - [[#638](https://github.com/edemaine/coauthor/issues/638)] -* Fix escaping search queries with backslash: `\:`, `\"`, `\|`, `\(`, `\)`, `\\` -* Newly allow escaping of `*` with `\*` - [[#29](https://github.com/edemaine/coauthor/issues/29)] +* Search improvements: [[#29](https://github.com/edemaine/coauthor/issues/29)] + * Search no longer supports quoting phrases with single quotes, so that it's + easier to search for possessives (e.g. `Erik's`). + [[#638](https://github.com/edemaine/coauthor/issues/638)] + * Search now sorts by the group's default sort, instead of by title. + * Fix escaping search queries with backslash: + `\:`, `\"`, `\|`, `\(`, `\)`, `\\` + * Newly allow escaping of `*` with `\*` ## 2023-11-17 diff --git a/client/search.coffee b/client/search.coffee index 830aec2f..9e2159ac 100644 --- a/client/search.coffee +++ b/client/search.coffee @@ -1,3 +1,5 @@ +import {groupDefaultSort} from '/lib/groups' +import {findMessageRoot, messagesSortedBy} from '/lib/messages' import {formatSearch, parseSearch} from '/lib/search' Template.search.onCreated -> @@ -18,13 +20,13 @@ topMessagesSearch = (group, search) -> msgs = messagesSearch group, search return [] unless msgs? msgs = msgs.fetch() - ## xxx should use default sort, not title sort? - msgs = _.sortBy msgs, (msg) -> - msg.group + '/' + - if msg.root - titleSort (Messages.findOne(msg.root)?.title ? '') - else - titleSort msg.title + ## Least significant: sort by group's default sort order -- + ## applying sort to message root, not the message + msgs = messagesSortedBy msgs, groupDefaultSort(group), findMessageRoot + ## Middle significant: sort roots before their descendants + msgs = _.sortBy msgs, (msg) -> msg.root? + ## Most significant: sort by group name + msgs = _.sortBy msgs, 'group' ## Form a set of all message IDs in match byId = {} for msg in msgs