diff --git a/CHANGELOG.md b/CHANGELOG.md index 7250461..8482167 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 830aec2..9e2159a 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