Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/modifyQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ describe('addAddHocFilter', () => {
operator: '=',
value: '["paperclip"]',
});
expect(result).toBe('status:200 AND attributes.tags:"paperclip"');
expect(result).toBe('(status:200) AND attributes.tags:"paperclip"');
});

it('handles single-element array with spaces in value', () => {
const result = addAddHocFilter('', {
key: 'attributes.tags',
Expand Down Expand Up @@ -163,6 +163,16 @@ describe('addAddHocFilter', () => {
});
expect(result).toBe('-attributes.tags:paperclip');
});

it('wraps an OR query before appending an AND filter', () => {
const result = addAddHocFilter('status:200 OR status:201', {
key: 'attributes.controller',
operator: '=',
value: 'BlogController',
});

expect(result).toBe('(status:200 OR status:201) AND attributes.controller:"BlogController"');
});
});

describe('scalar value filters', () => {
Expand All @@ -181,7 +191,7 @@ describe('addAddHocFilter', () => {
operator: '=',
value: 'BlogController',
});
expect(result).toBe('status:200 AND attributes.controller:"BlogController"');
expect(result).toBe('(status:200) AND attributes.controller:"BlogController"');
});

it('renders numeric equality filters as unquoted literals', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/lucene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function concatenate(query: string, filter: string, operator?: 'AND'|'OR'
return filter;
}

return operator ? `${query} ${operator} ${filter}` : `${query} ${filter}`
return operator ? `(${query}) ${operator} ${filter}` : `(${query}) ${filter}`
Comment thread
chai-masalla marked this conversation as resolved.
}

export class LuceneQuery {
Expand Down