Override default sort orders with --sort

This commit is contained in:
Mickaël Menu 2021-02-27 11:23:16 +01:00
parent 65521769c2
commit 27eda3deb6
No known key found for this signature in database
GPG Key ID: 53D73664CD359895
6 changed files with 25 additions and 6 deletions

View File

@ -12,7 +12,7 @@ import (
)
func init() {
Init("en", &util.NullLogger, &styler{})
Init("en", true, &util.NullLogger, &styler{})
}
// styler is a test double for core.Styler

View File

@ -337,7 +337,7 @@ func (d *NoteDAO) findRows(opts note.FinderOpts) (*sql.Rows, error) {
snippetCol := `n.lead`
joinClauses := make([]string, 0)
whereExprs := make([]string, 0)
orderTerms := make([]string, 0)
additionalOrderTerms := make([]string, 0)
args := make([]interface{}, 0)
groupBy := ""
@ -419,7 +419,7 @@ func (d *NoteDAO) findRows(opts note.FinderOpts) (*sql.Rows, error) {
case note.MatchFilter:
snippetCol = `snippet(notes_fts, 2, '<zk:match>', '</zk:match>', '…', 20) as snippet`
joinClauses = append(joinClauses, "JOIN notes_fts ON n.id = notes_fts.rowid")
orderTerms = append(orderTerms, `bm25(notes_fts, 1000.0, 500.0, 1.0)`)
additionalOrderTerms = append(additionalOrderTerms, `bm25(notes_fts, 1000.0, 500.0, 1.0)`)
whereExprs = append(whereExprs, "notes_fts MATCH ?")
args = append(args, fts5.ConvertQuery(string(filter)))
@ -493,9 +493,11 @@ func (d *NoteDAO) findRows(opts note.FinderOpts) (*sql.Rows, error) {
}
}
orderTerms := []string{}
for _, sorter := range opts.Sorters {
orderTerms = append(orderTerms, orderTerm(sorter))
}
orderTerms = append(orderTerms, additionalOrderTerms...)
orderTerms = append(orderTerms, `n.title ASC`)
query := ""

View File

@ -466,6 +466,23 @@ func TestNoteDAOFindMatch(t *testing.T) {
)
}
func TestNoteDAOFindMatchWithSort(t *testing.T) {
testNoteDAOFindPaths(t,
note.FinderOpts{
Filters: []note.Filter{note.MatchFilter("daily | index")},
Sorters: []note.Sorter{
{Field: note.SortPath, Ascending: false},
},
},
[]string{
"log/2021-02-04.md",
"log/2021-01-04.md",
"log/2021-01-03.md",
"index.md",
},
)
}
func TestNoteDAOFindInPath(t *testing.T) {
testNoteDAOFindPaths(t,
note.FinderOpts{

View File

@ -19,7 +19,7 @@ func TestParseDefaultConfig(t *testing.T) {
Extension: "md",
BodyTemplatePath: opt.NullString,
IDOptions: IDOptions{
Length: 5,
Length: 4,
Charset: CharsetAlphanum,
Case: CaseLower,
},

2
go
View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
VERSION=`git describe --tags 2> /dev/null`
BUILD=`git rev-parse --short HEAD`

2
run
View File

@ -1,2 +1,2 @@
#!/bin/sh
#!/bin/bash
./go run main.go $@