fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

Special case symbol search regex .* (#34)

* Small symbol search optimization

* Add unit test for property

+48 -3
+10 -3
matchtree.go
··· 148 148 type symbolRegexpMatchTree struct { 149 149 matchTree 150 150 regexp *regexp.Regexp 151 + all bool // skips regex match if .* 151 152 152 153 reEvaluated bool 153 154 found []*candidateMatch ··· 171 172 172 173 found := t.found[:0] 173 174 for i, sec := range sections { 174 - idx := t.regexp.FindIndex(content[sec.Start:sec.End]) 175 - if idx == nil { 176 - continue 175 + var idx []int 176 + if t.all { 177 + idx = []int{0, int(sec.End - sec.Start)} 178 + } else { 179 + idx = t.regexp.FindIndex(content[sec.Start:sec.End]) 180 + if idx == nil { 181 + continue 182 + } 177 183 } 178 184 179 185 cm := &candidateMatch{ ··· 779 785 780 786 return &symbolRegexpMatchTree{ 781 787 regexp: regexp, 788 + all: regexp.String() == "(?i)(?-s:.)*", 782 789 matchTree: subMT, 783 790 }, nil 784 791 }
+38
matchtree_test.go
··· 17 17 import ( 18 18 "reflect" 19 19 "testing" 20 + 21 + "github.com/google/zoekt/query" 20 22 ) 21 23 22 24 func Test_breakOnNewlines(t *testing.T) { ··· 152 154 }) 153 155 } 154 156 } 157 + 158 + func TestSymbolMatchRegexAll(t *testing.T) { 159 + tests := []struct { 160 + query string 161 + all bool 162 + }{ 163 + {query: ".*", all: true}, 164 + {query: "(a|b)", all: false}, 165 + {query: "b.r", all: false}, 166 + } 167 + 168 + for _, tt := range tests { 169 + q, err := query.Parse("sym:" + tt.query) 170 + if err != nil { 171 + t.Errorf("Error parsing query: %s", "sym:"+tt.query) 172 + continue 173 + } 174 + 175 + d := &indexData{} 176 + mt, err := d.newMatchTree(q) 177 + if err != nil { 178 + t.Errorf("Error creating match tree from query: %s", q) 179 + continue 180 + } 181 + 182 + regexMT, ok := mt.(*symbolRegexpMatchTree) 183 + if !ok { 184 + t.Errorf("Expected symbol regex match tree from query: %s, got %v", q, mt) 185 + continue 186 + } 187 + 188 + if regexMT.all != tt.all { 189 + t.Errorf("Expected property all: %t from query: %s", tt.all, q) 190 + } 191 + } 192 + }