Skip to content

Commit

Permalink
Fix filtering tags whilst showing tag connections
Browse files Browse the repository at this point in the history
  • Loading branch information
msp301 committed May 26, 2023
1 parent bee3707 commit 97d3fab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var tagsCmd = &cobra.Command{
}

if connections, err := cmd.Flags().GetBool("connections"); err == nil && connections {
for _, tagConnection := range book().TagConnections() {
for _, tagConnection := range book().TagConnections(searchTag) {
fmt.Printf("%d %s\n", tagConnection.Connections, tagConnection.Tag)
}
return
Expand Down
22 changes: 13 additions & 9 deletions notebook/notebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,9 @@ func (book *Notebook) LinkCount() int {

func (book *Notebook) Tags(search string) []string {
var tags []string
traversal := graph.Traversal(book.Notes)
for _, tag := range traversal.V().HasLabel("tag").Values("Value") {
tagStr := fmt.Sprint(tag)
if util.Matches(search, tagStr) {
tags = append(tags, tagStr)
}
tagConnections := book.tagConnections(search)
for _, tagConnection := range tagConnections {
tags = append(tags, tagConnection.Tag)
}
sort.Strings(tags)
return tags
Expand All @@ -287,14 +284,21 @@ type TagConnection struct {
Connections int
}

func (book *Notebook) TagConnections() []TagConnection {
func (book *Notebook) tagConnections(search string) []TagConnection {
var tagConnections []TagConnection
traversal := graph.Traversal(book.Notes)
for vertex := range traversal.V().HasLabel("tag").Iterate() {
tag := fmt.Sprint(vertex.Properties["Value"])
tagConnection := TagConnection{Tag: tag, Connections: len(book.Notes.Adjacency[vertex.Id])}
tagConnections = append(tagConnections, tagConnection)
if util.Matches(search, tag) {
tagConnection := TagConnection{Tag: tag, Connections: len(book.Notes.Adjacency[vertex.Id])}
tagConnections = append(tagConnections, tagConnection)
}
}
return tagConnections
}

func (book *Notebook) TagConnections(search string) []TagConnection {
tagConnections := book.tagConnections(search)
sort.SliceStable(tagConnections, func(i, j int) bool {
return tagConnections[i].Connections > tagConnections[j].Connections
})
Expand Down

0 comments on commit 97d3fab

Please sign in to comment.