Skip to content

Commit 10bb5fa

Browse files
committed
Fix searching for ticket references
Allow hyphen to be considered part of a search word when perfoming a fuzzy search. 'zb' is trying to limit what it considers a search token to reduce false positives but not allowing hyphen has stopped searching by JIRA ticket reference and gathering notes for that ticket.
1 parent 804791e commit 10bb5fa

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

notebook/search_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package notebook
2+
3+
import (
4+
"github.com/msp301/zb/graph"
5+
"github.com/msp301/zb/parser"
6+
"reflect"
7+
"testing"
8+
)
9+
10+
func TestSearch(t *testing.T) {
11+
g := graph.New()
12+
g.AddVertex(graph.Vertex{Id: 1, Label: "note", Properties: map[string]interface{}{"Value": parser.Note{Content: "foo bar", Start: 1}}})
13+
g.AddVertex(graph.Vertex{Id: 2, Label: "note", Properties: map[string]interface{}{"Value": parser.Note{Content: "# TICKET-123 title", Start: 1}}})
14+
book := &Notebook{Notes: g}
15+
16+
got := book.Search("ticket-123")
17+
want := []Result{{Context: "# TICKET-123 title", Line: 1, Value: graph.Vertex{Id: 2, Label: "note", Properties: map[string]interface{}{"Value": parser.Note{Content: "# TICKET-123 title", Start: 1}}}}}
18+
19+
if !reflect.DeepEqual(got, want) {
20+
t.Fatalf("Expected: %+v\nGot: %+v", want, got)
21+
}
22+
}

util/paragraph.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77
)
88

9-
var noiseRegex = regexp.MustCompile(`[^\s\w#.]`)
9+
var noiseRegex = regexp.MustCompile(`[^\s\w#.-]`)
1010

1111
func ParagraphMatches(content string, query string) bool {
1212
content = noiseRegex.ReplaceAllString(content, " ")

0 commit comments

Comments
 (0)