Skip to content

Commit

Permalink
add option to create compound group index (#5174)
Browse files Browse the repository at this point in the history
  • Loading branch information
brimoor authored Nov 22, 2024
1 parent c5a74a5 commit 7020152
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions fiftyone/operators/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,11 +1083,31 @@ def resolve_input(self, ctx):
description="Whether to add a uniqueness constraint to the index",
)

if ctx.dataset.media_type == fom.GROUP:
inputs.bool(
"group_index",
default=True,
required=False,
label="Group index",
description=(
"Whether to also add a compound group index. This "
"optimizes sidebar queries when viewing specific group "
"slice(s)"
),
)

return types.Property(inputs, view=types.View(label="Create index"))

def execute(self, ctx):
field_name = ctx.params["field_name"]
unique = ctx.params.get("unique", False)
group_index = ctx.params.get("group_index", False)

if ctx.dataset.media_type == fom.GROUP and group_index:
group_path = ctx.dataset.group_field + ".name"
index_spec = [(group_path, 1), (field_name, 1)]

ctx.dataset.create_index(index_spec, unique=unique, wait=False)

ctx.dataset.create_index(field_name, unique=unique, wait=False)

Expand Down

0 comments on commit 7020152

Please sign in to comment.