MCPcopy Index your code
hub / github.com/simstudioai/sim / parseQuery

Function parseQuery

apps/sim/lib/logs/query-parser.ts:40–76  ·  view source on GitHub ↗
(query: string)

Source from the content-addressed store, hash-verified

38 * Parse a search query string into structured filters and text search
39 */
40export function parseQuery(query: string): ParsedQuery {
41 const filters: ParsedFilter[] = []
42 const tokens: string[] = []
43
44 const filterRegex = /(\w+):((?:[><!]=?|=)?(?:"[^"]*"|[^\s]+))/g
45
46 let lastIndex = 0
47 let match
48
49 while ((match = filterRegex.exec(query)) !== null) {
50 const [fullMatch, field, valueWithOperator] = match
51
52 const beforeText = query.slice(lastIndex, match.index).trim()
53 if (beforeText) {
54 tokens.push(beforeText)
55 }
56
57 const parsedFilter = parseFilter(field, valueWithOperator)
58 if (parsedFilter) {
59 filters.push(parsedFilter)
60 } else {
61 tokens.push(fullMatch)
62 }
63
64 lastIndex = match.index + fullMatch.length
65 }
66
67 const remainingText = query.slice(lastIndex).trim()
68 if (remainingText) {
69 tokens.push(remainingText)
70 }
71
72 return {
73 filters,
74 textSearch: tokens.join(' ').trim(),
75 }
76}
77
78/**
79 * Parse a single field:value filter

Callers 4

LogsFunction · 0.90
useSearchStateFunction · 0.90
applyFilterParamsFunction · 0.90

Calls 3

parseFilterFunction · 0.85
joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected