mirror of
https://github.com/mickael-menu/zk
synced 2024-11-07 15:20:21 +00:00
Override default sort orders with --sort
This commit is contained in:
parent
65521769c2
commit
27eda3deb6
@ -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
|
||||
|
@ -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 := ""
|
||||
|
@ -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{
|
||||
|
@ -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
2
go
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
VERSION=`git describe --tags 2> /dev/null`
|
||||
BUILD=`git rev-parse --short HEAD`
|
||||
|
Loading…
Reference in New Issue
Block a user