Skip to content

Commit

Permalink
Sort 'tag' results
Browse files Browse the repository at this point in the history
Finding that I'm piping output through 'sort' often when searching by
tags so default to outputting notes in chronological order so that
sorting no longer relies on the path location but instead the note ID
(which will result in chronological order as IDs are a date
representation).
  • Loading branch information
msp301 committed Oct 6, 2023
1 parent 212c08e commit 9c980ce
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions notebook/notebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (book *Notebook) MatchedTags(searchTags ...string) []matchedTag {
return tagVerticesSlice
}

func (book *Notebook) TagIntersection(matchedTags []matchedTag) map[uint64]graph.Vertex {
func (book *Notebook) TagIntersection(matchedTags []matchedTag) []graph.Vertex {
var intersection = make(map[uint64]graph.Vertex)
var mostConnectedVertex = matchedTags[0]
VERTEX:
Expand All @@ -315,7 +315,20 @@ VERTEX:
intersection[vertexId] = book.Notes.Vertices[vertexId]
}

return intersection
var sortedVertices []uint64
for vertexId := range intersection {
sortedVertices = append(sortedVertices, vertexId)
}
sort.SliceStable(sortedVertices, func(i, j int) bool {
return sortedVertices[i] < sortedVertices[j]
})

var sortedIntersection []graph.Vertex
for _, vertexId := range sortedVertices {
sortedIntersection = append(sortedIntersection, intersection[vertexId])
}

return sortedIntersection
}

func (book *Notebook) addTag(tag string) uint64 {
Expand Down

0 comments on commit 9c980ce

Please sign in to comment.