MCPcopy Index your code
hub / github.com/codechenx/FastTableViewer / performSearch

Function performSearch

utils.go:287–351  ·  view source on GitHub ↗

performSearch searches for a query string in the buffer and stores results Supports both plain text and regex search modes with parallel column scanning

(b *Buffer, query string, useRegex bool, caseSensitive bool)

Source from the content-addressed store, hash-verified

285// performSearch searches for a query string in the buffer and stores results
286// Supports both plain text and regex search modes with parallel column scanning
287func performSearch(b *Buffer, query string, useRegex bool, caseSensitive bool) []SearchResult {
288 b.mu.RLock()
289 defer b.mu.RUnlock()
290
291 // Compile regex if in regex mode
292 var re *regexp.Regexp
293 var err error
294 if useRegex {
295 if !caseSensitive {
296 query = "(?i)" + query
297 }
298 re, err = regexp.Compile(query)
299 if err != nil {
300 return []SearchResult{}
301 }
302 } else if !caseSensitive {
303 query = strings.ToLower(query)
304 }
305
306 // Parallel search across columns for better performance
307 resultChan := make(chan []SearchResult, b.colLen)
308 var wg sync.WaitGroup
309
310 for c := 0; c < b.colLen; c++ {
311 wg.Add(1)
312 go func(col int) {
313 defer wg.Done()
314 var colResults []SearchResult
315
316 for r := 0; r < b.rowLen; r++ {
317 cellText := b.cont[r][col]
318
319 var matches bool
320 if useRegex {
321 matches = re.MatchString(cellText)
322 } else {
323 if caseSensitive {
324 matches = strings.Contains(cellText, query)
325 } else {
326 matches = strings.Contains(strings.ToLower(cellText), query)
327 }
328 }
329
330 if matches {
331 colResults = append(colResults, SearchResult{Row: r, Col: col})
332 }
333 }
334
335 resultChan <- colResults
336 }(c)
337 }
338
339 go func() {
340 wg.Wait()
341 close(resultChan)
342 }()
343
344 // Collect results from all columns

Callers 3

TestPerformSearchFunction · 0.85
TestPerformSearchRegexFunction · 0.85
drawUIFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestPerformSearchFunction · 0.68
TestPerformSearchRegexFunction · 0.68