-
Notifications
You must be signed in to change notification settings - Fork 0
feat(query): add field existence, regex, +/- prefix, boost, and ? wildcard query support #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
3
commits into
main
Choose a base branch
from
copilot/add-lucene-query-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| /** | ||
| * lucene-query.spec.mjs — Lucene-style query feature tests. | ||
| * | ||
| * Covers: field existence (field:*), regex (field:/regex/), FTS (bare keyword | ||
| * and quoted phrase), required/prohibited (+/-), and wildcard queries. | ||
| */ | ||
|
|
||
| import { test, expect } from '@playwright/test'; | ||
| import { portForTestFile, startServer, stopServer, postJSON } from './helpers.mjs'; | ||
|
|
||
| let server; | ||
| let baseURL; | ||
|
|
||
| /** Logs with varied fields and messages for query testing. */ | ||
| const TEST_LINES = [ | ||
| // logs with request_id | ||
| JSON.stringify({ level: 'INFO', msg: 'connection timeout', time: '2026-02-18T10:01:00Z', service: 'api-gateway', request_id: 'req-001' }), | ||
| JSON.stringify({ level: 'INFO', msg: 'connection refused', time: '2026-02-18T10:02:00Z', service: 'api-edge', request_id: 'req-002' }), | ||
| // logs without request_id | ||
| JSON.stringify({ level: 'WARN', msg: 'all good', time: '2026-02-18T10:03:00Z', service: 'auth-service' }), | ||
| JSON.stringify({ level: 'ERROR', msg: 'internal error', time: '2026-02-18T10:04:00Z', service: 'auth-service' }), | ||
| JSON.stringify({ level: 'ERROR', msg: 'gateway error', time: '2026-02-18T10:05:00Z', service: 'api-gateway', request_id: 'req-005' }), | ||
| JSON.stringify({ level: 'DEBUG', msg: 'debug trace', time: '2026-02-18T10:06:00Z', service: 'api-edge' }), | ||
| ]; | ||
|
|
||
| test.describe('lucene-query', () => { | ||
| test.beforeAll(async ({}, workerInfo) => { | ||
| const port = portForTestFile(workerInfo); | ||
| server = await startServer(port, { lines: TEST_LINES }); | ||
| baseURL = `http://localhost:${port}`; | ||
| }); | ||
|
|
||
| test.afterAll(async () => { | ||
| await stopServer(server); | ||
| }); | ||
|
|
||
| test('field existence: request_id:* returns only logs with that field', async ({ page }) => { | ||
| await page.goto(baseURL); | ||
| const result = await postJSON(page, '/query', { query: 'request_id:*', limit: 100 }); | ||
| expect(result.status).toBe(200); | ||
| const logs = result.body.logs; | ||
| expect(logs.length).toBeGreaterThan(0); | ||
| // Every returned log must have request_id | ||
| for (const log of logs) { | ||
| expect(log.fields).toHaveProperty('request_id'); | ||
| } | ||
| // Logs without request_id must not appear | ||
| const withoutRequestId = logs.filter((l) => !l.fields?.request_id); | ||
| expect(withoutRequestId).toHaveLength(0); | ||
| }); | ||
|
|
||
| test('field existence: non-existent field returns no results', async ({ page }) => { | ||
| await page.goto(baseURL); | ||
| const result = await postJSON(page, '/query', { query: 'nonexistent_field:*', limit: 100 }); | ||
| expect(result.status).toBe(200); | ||
| expect(result.body.logs).toHaveLength(0); | ||
| }); | ||
|
|
||
| test('regex: service:/^api-(gateway|edge)$/ matches only api services', async ({ page }) => { | ||
| await page.goto(baseURL); | ||
| const result = await postJSON(page, '/query', { | ||
| query: 'service:/^api-(gateway|edge)$/', | ||
| limit: 100, | ||
| }); | ||
| expect(result.status).toBe(200); | ||
| const logs = result.body.logs; | ||
| expect(logs.length).toBeGreaterThan(0); | ||
| for (const log of logs) { | ||
| expect(['api-gateway', 'api-edge']).toContain(log.fields?.service); | ||
| } | ||
| // auth-service must not appear | ||
| const authLogs = logs.filter((l) => l.fields?.service === 'auth-service'); | ||
| expect(authLogs).toHaveLength(0); | ||
| }); | ||
|
|
||
| test('FTS: bare keyword "timeout" matches message containing word', async ({ page }) => { | ||
| await page.goto(baseURL); | ||
| const result = await postJSON(page, '/query', { query: 'timeout', limit: 100 }); | ||
| expect(result.status).toBe(200); | ||
| const logs = result.body.logs; | ||
| expect(logs.length).toBeGreaterThan(0); | ||
| for (const log of logs) { | ||
| expect(log.message.toLowerCase()).toContain('timeout'); | ||
| } | ||
| }); | ||
|
|
||
| test('FTS: quoted phrase "connection refused" matches the exact phrase', async ({ page }) => { | ||
| await page.goto(baseURL); | ||
| const result = await postJSON(page, '/query', { | ||
| query: '"connection refused"', | ||
| limit: 100, | ||
| }); | ||
| expect(result.status).toBe(200); | ||
| const logs = result.body.logs; | ||
| expect(logs.length).toBeGreaterThan(0); | ||
| for (const log of logs) { | ||
| expect(log.message.toLowerCase()).toContain('connection refused'); | ||
| } | ||
| // "connection timeout" must NOT appear | ||
| const nonMatchingLogs = logs.filter((l) => l.message.toLowerCase().includes('timeout') && !l.message.toLowerCase().includes('refused')); | ||
| expect(nonMatchingLogs).toHaveLength(0); | ||
| }); | ||
|
|
||
| test('required/prohibited: +level:ERROR -service:auth returns only non-auth ERRORs', async ({ page }) => { | ||
| await page.goto(baseURL); | ||
| const result = await postJSON(page, '/query', { | ||
| query: '+level:ERROR -service:auth', | ||
| limit: 100, | ||
| }); | ||
| expect(result.status).toBe(200); | ||
| const logs = result.body.logs; | ||
| expect(logs.length).toBeGreaterThan(0); | ||
| for (const log of logs) { | ||
| expect(log.level).toBe('ERROR'); | ||
| expect(log.fields?.service).not.toContain('auth'); | ||
| } | ||
| }); | ||
|
|
||
| test('wildcard: service:api* matches all api-prefixed services', async ({ page }) => { | ||
| await page.goto(baseURL); | ||
| const result = await postJSON(page, '/query', { query: 'service:api*', limit: 100 }); | ||
| expect(result.status).toBe(200); | ||
| const logs = result.body.logs; | ||
| expect(logs.length).toBeGreaterThan(0); | ||
| for (const log of logs) { | ||
| expect(log.fields?.service).toMatch(/^api/); | ||
| } | ||
| // auth-service must not appear | ||
| const authLogs = logs.filter((l) => l.fields?.service === 'auth-service'); | ||
| expect(authLogs).toHaveLength(0); | ||
| }); | ||
|
|
||
| test('UI: regex and +/- queries highlighted correctly', async ({ page }) => { | ||
| await page.goto(baseURL); | ||
| const searchInput = page.locator('.search-editor-input'); | ||
| await expect(searchInput).toBeVisible(); | ||
|
|
||
| // Regex literal should get hl-regex class | ||
| await searchInput.fill('service:/^api-(gateway|edge)$/'); | ||
| await page.waitForTimeout(100); | ||
| const hasRegexHighlight = await page.evaluate( | ||
| () => !!document.querySelector('.search-highlight .hl-regex'), | ||
| ); | ||
| expect(hasRegexHighlight).toBeTruthy(); | ||
|
|
||
| // +/- prefix operators should get hl-op class | ||
| await searchInput.fill('+level:ERROR -service:auth'); | ||
| await page.waitForTimeout(100); | ||
| const opSpans = await page.evaluate( | ||
| () => Array.from(document.querySelectorAll('.search-highlight .hl-op')).map((e) => e.textContent), | ||
| ); | ||
| expect(opSpans).toContain('+'); | ||
| expect(opSpans).toContain('-'); | ||
|
|
||
| // ? wildcard should get hl-wildcard class | ||
| await searchInput.fill('service:api-?'); | ||
| await page.waitForTimeout(100); | ||
| const hasWildcardHighlight = await page.evaluate( | ||
| () => !!document.querySelector('.search-highlight .hl-wildcard'), | ||
| ); | ||
| expect(hasWildcardHighlight).toBeTruthy(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extractRegexcurrently treats any token ending in/as a complete regex literal, butreadTokencan stop early at(or). For a valid query likepath:/foo\/(bar|baz)/, the partial token seen here is"/foo\\/"; this branch returnsfoo\\andregexp.Compilefails, so valid regex queries are rejected whenever an escaped slash appears before a parenthesized part.Useful? React with 👍 / 👎.