Skip to content
Merged
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
15 changes: 14 additions & 1 deletion src/components/QueryEditor/FilterEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const FilterEditorRow = ({ value, onSubmit }: FilterEditorRowProps) => {
}}
/>
</div>
{!['exists', 'not exists'].includes(value.filter.operator) && (
{['=', '!=', 'term', 'not term'].includes(value.filter.operator) && (
<Input
ref={valueInputRef}
placeholder="Value"
Expand All @@ -143,6 +143,19 @@ export const FilterEditorRow = ({ value, onSubmit }: FilterEditorRowProps) => {
}}
/>
)}
{['in', 'not in'].includes(value.filter.operator) && (
<Input
ref={valueInputRef}
placeholder="Space-delimited values"
value={value.filter.value}
onChange={(e) => dispatch(changeFilterValue({ id: value.id, value: e.currentTarget.value }))}
onKeyUp={(e) => {
if (e.key === 'Enter') {
onSubmit();
}
}}
/>
)}
</InlineSegmentGroup>
</>
);
Expand Down
5 changes: 4 additions & 1 deletion src/datasource/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,10 @@ export class BaseQuickwitDataSource
if (!adhocFilters) {
return query;
}
let finalQuery = query;

// Surround the query with () to ensure that the filters are properly AND'd
let finalQuery = '(' + query + ')';

adhocFilters.forEach((filter) => {
finalQuery = addAddHocFilter(finalQuery, filter);
});
Expand Down
18 changes: 18 additions & 0 deletions src/modifyQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ export function addAddHocFilter(query: string, filter: AdHocVariableFilter): str
case 'not exists':
addHocFilter = `-${key}:*`;
break;
case 'in':
addHocFilter = createAdhocFilterIn(key, value);
break;
case 'not in':
addHocFilter = `(NOT (${createAdhocFilterIn(key, value)}))`;
break;
}
return concatenate(query, addHocFilter);
}

function createAdhocFilterIn(key: string, value: string): string {
const values = value.split(' ');

// OR is faster than IN for smaller number of values
if (values.length < 10) {
const conditions = values.map(v => `${key}:${v}`);
return `(${conditions.join(' OR ')})`;
}

return `${key}:IN [${value}]`;
}
2 changes: 2 additions & 0 deletions src/queryDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const filterOperations = [
{ label: 'not term', value: 'not term' },
{ label: 'exists', value: 'exists' },
{ label: 'not exists', value: 'not exists' },
{ label: 'in', value: 'in' },
{ label: 'not in', value: 'not in' },
];

export function defaultFilter(id = newFilterId()): QueryFilter {
Expand Down