Skip to content

Commit

Permalink
Add filter options along source and signal fields (#596)
Browse files Browse the repository at this point in the history
Add more options in the search menu to make filtering/sorting easier:

- Filter signal fields by EXISTS (e.g. emails, ip addresses, etc)
- Sorting both source and signals fields


https://github.com/lilacai/lilac/assets/2294279/b14ef225-2c50-4c52-88cf-4eabcbb03f32
  • Loading branch information
dsmilkov authored Aug 25, 2023
1 parent 910e9e2 commit be25f41
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
$: schema = schemaQuery && $schemaQuery?.data;
$: stringFields = schema
? childFields(schema).filter(f => f.dtype === 'string' && !isSignalField(f, schema!))
? childFields(schema).filter(f => f.dtype === 'string' && !isSignalField(f))
: [];
$: fields = stringFields.sort((a, b) => {
const aIsIndexed = childFields(a).some(
Expand All @@ -80,7 +80,7 @@
$: {
// Auto-select the first path.
if (fields && fields.length > 0 && path === undefined) {
path = deserializePath(fields[0].path);
path = fields[0].path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
.filter(field => (filter ? filter(field) : true))
: null;
$: sourceFields = fields?.filter(f => $schema.data && !isSignalField(f, $schema.data));
$: sourceFields = fields?.filter(f => $schema.data && !isSignalField(f));
function formatField(field: LilacField): string {
return `${field.path.join('.')} (${field.dtype})`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
$: schema = $schemaQuery.data;
$: pathId = path ? serializePath(path) : undefined;
$: sourceFields = schema
? childFields(schema).filter(f => !isSignalField(f, schema!) && f.dtype != null)
? childFields(schema).filter(f => !isSignalField(f) && f.dtype != null)
: [];
$: indexedFields = sourceFields.filter(f =>
childFields(f).some(f => f.signal != null && childFields(f).some(f => f.dtype === 'embedding'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
isSignalRootField,
isSortableField,
serializePath,
type LilacField,
type LilacSchema
type LilacField
} from '$lilac';
import {Modal, OverflowMenu, OverflowMenuItem} from 'carbon-components-svelte';
import {InProgress} from 'carbon-icons-svelte';
import {Command, triggerCommand} from '../commands/Commands.svelte';
import {hoverTooltip} from '../common/HoverTooltip';
export let field: LilacField;
export let schema: LilacSchema;
let deleteSignalOpen = false;
Expand All @@ -31,7 +29,7 @@
const datasetStore = getDatasetContext();
const deleteSignal = deleteSignalMutation();
$: isSignal = isSignalField(field, schema);
$: isSignal = isSignalField(field);
$: isSignalRoot = isSignalRootField(field);
$: isPreview = isPreviewSignal($datasetStore.selectRowsSchema?.data || null, field.path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
let preferredEmbedding: string | undefined = $appSettings.embedding;
$: mediaFields = petals(schema).filter(
f => f.dtype === 'string' && !pathIsEqual(f.path, [ROWID]) && !isSignalField(f, schema)
f => f.dtype === 'string' && !pathIsEqual(f.path, [ROWID]) && !isSignalField(f)
);
$: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
checkedFields.push(field);
checkedFields = checkedFields;
} else {
checkedFields = checkedFields.filter(f => f !== field);
checkedFields = checkedFields.filter(f => !pathIsEqual(f.path, field.path));
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
return {sourceFields: null, enrichedFields: null};
}
const petalFields = petals(schema).filter(field => ['embedding'].indexOf(field.dtype!) === -1);
const sourceFields = petalFields.filter(f => !isSignalField(f, schema));
const sourceFields = petalFields.filter(f => !isSignalField(f));
const enrichedFields = childFields(schema)
.filter(f => isSignalRootField(f))
.filter(f => !childFields(f).some(f => f.dtype === 'embedding'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {queryConcept} from '$lib/queries/conceptQueries';
import {getDatasetContext} from '$lib/stores/datasetStore';
import {getDatasetViewContext} from '$lib/stores/datasetViewStore';
import {getSearches, getSort} from '$lib/view_utils';
import {displayPath, getSearches, getSort} from '$lib/view_utils';
import {
deserializePath,
formatValue,
Expand Down Expand Up @@ -86,7 +86,7 @@
.map(field => {
return {
path: field.path,
text: serializePath(field.path.slice(1)),
text: displayPath(field.path.slice(1)),
disabled: false
};
})
Expand Down
22 changes: 16 additions & 6 deletions web/blueprint/src/lib/components/datasetView/FilterPill.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script lang="ts">
import {getDatasetViewContext} from '$lib/stores/datasetViewStore';
import {displayPath, shortFieldName} from '$lib/view_utils';
import {
deserializePath,
formatValue,
serializePath,
type BinaryFilter,
type ListFilter,
type Op,
Expand Down Expand Up @@ -31,8 +31,11 @@
$: formattedValue = formatValue(filter.value || 'false');
$: path = deserializePath(filter.path);
$: tooltip = `${serializePath(filter.path)} ${FILTER_SHORTHANDS[filter.op]} ${formattedValue}`;
$: shortenPath = path.at(-1);
$: tooltip =
filter.op === 'exists'
? `has ${displayPath(path)}`
: `${displayPath(path)} ${FILTER_SHORTHANDS[filter.op]} ${formattedValue}`;
$: shortenPath = shortFieldName(path);
</script>

<div class="filter-pill items-center" use:hoverTooltip={{text: tooltip}}>
Expand All @@ -48,9 +51,13 @@
})}
on:remove={() => datasetViewStore.removeFilter(filter)}
>
<span class="font-mono">{hidePath ? '' : shortenPath}</span>
{FILTER_SHORTHANDS[filter.op]}
{formattedValue}
{#if filter.op === 'exists'}
has <span class="font-mono">{hidePath ? '' : shortenPath}</span>
{:else}
<span class="font-mono">{hidePath ? '' : shortenPath}</span>
{FILTER_SHORTHANDS[filter.op]}
{formattedValue}
{/if}
</RemovableTag>
</div>

Expand All @@ -62,4 +69,7 @@
:global(.filter-pill .bx--tooltip__content) {
@apply flex flex-col items-center;
}
:global(.search-container .bx--list-box__menu) {
max-height: 26rem !important;
}
</style>
Loading

0 comments on commit be25f41

Please sign in to comment.