Repository navigation
feat(search): filter by artifact property (prop:KEY=VALUE) - #466
Merged
Merged
Conversation
GET /api/v1/search and the MCP search_artifacts tool keep the artifacts carrying a property: prop:KEY=VALUE in q, or the repeatable prop parameter for values with spaces. Exact match, all filters must hold, at most 10; q may be left out, as with flagged=true. A filter matches the id the web UI and oa store properties under (a package_files row of the same repository); docker images are left out for now. With prop no repositories are returned. Malformed filters are 400 invalid_filter (a tool error on MCP). Each filter is applied in the shape that fits how many properties match, decided by a bounded count: up to 1000 by an id array pushed into the search source, so package_files is probed by primary key (Postgres cannot push a join into the UNION ALL); more as a correlated EXISTS, which the capped search can stop early. Migration 029 adds idx_artifact_properties_key_value (key, value) INCLUDE (artifact_ref_id), built concurrently. The upgrade notes get a new "Unreleased" section with this and the oa upload content-type change of openartifact#460, which was filed under 0.23.0 although it merged after that release. Closes openartifact#459 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
|
Thanks! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #459, with your answers: both forms,
qoptional withprop, at most 10 filters, noprop:in the too-broad hint, docker left out.API
prop:KEY=VALUEinq, and the repeatablepropparameter (prop=client%3DACME%20Corp) for values with spaces. Split at the first=, exact match on key and value, all filters must hold.qmay be left out when apropfilter is given, as withflagged=true.oastore properties under: a livepackage_filesrow of the same repository (a property stored in one repository under another repository's file id doesn't match). Docker rows are excluded (s.format <> 'docker'drops the branch); I didn't confirm their id mapping, so they're left for a follow-up.prop, as withsha256:andflagged.search.CheckPropFilters(key 1 to 255 bytes, value up to 4096, valid UTF-8, no control characters in the key, no NUL in the value, at most 10) is shared by the handler (400 invalid_filter) andsearch_artifacts(tool error, before any query).The plan check, and why there are two shapes
You asked for the plan with
qomitted on a seeded database. I measured withEXPLAIN ANALYZEon the scope seed plus one repository of 300,000 files (seeded with triggers off: the per-row triggers ofpackage_filesmake a bulk insert crawl), withstatus=drafton every file,status=approvedon 25, andchannel=betaon about 5,000:(repo, id) IN (…)EXISTSstatus=approved(25)channel=beta(~5k)status=draft(300k)status=draft+name:f777Two findings decided the shape:
UNION ALLsearch source, so a semi-join always reads every file. For few matches the fix is to compute the matching file ids first, as an array, which is pushed into each branch asf.id = ANY(…)and probespackage_files_pkey.EXISTSis better: the capped search stops early, and with a selectiveqit only probes the rows that are left. The semi-join instead collects and de-duplicates every match first.So
Executor.planPropscounts each filter's properties (bounded,LIMIT 1001) and applies it by id array up to 1000 matches, asEXISTSabove. Both shapes select the same rows.Index:
029_artifact_properties_key_value.no_tx.sqladds(key, value) INCLUDE (artifact_ref_id), builtCONCURRENTLYwith the invalid-index guard of021. It serves the id array (index-only, 25 rows instead of everystatusrow through(repository_id, key)) and the bounded count. The(artifact_ref_id, key, value)index you mentioned turned out not to be needed: theEXISTSprobe is fast withartifact_refs (repository_id, artifact_path)andidx_artifact_properties_ref_id, so I didn't add a second index.Tests
prop_filter_integration_test.go: every case runs in both shapes with the same expected rows:qomitted (readable repositories only, the cross-repository id doesn't match), with text, two filters, a value with a space, exact match (no prefix), no match, withformat, andgroup=packagereturning the latest matching version.TestPlanPropsPicksTheShape(rare → id array, more than 1000 →EXISTS),TestPropFilterPlans(enable_seqscan = offlikeTestVulnScanOverviewUsesIndexes: the id array usesidx_artifact_properties_key_valueandpackage_files_pkey;EXISTSis a nested-loop semi-join, never a hash semi-join over all matches), and no repository hits withprop.CheckPropFilters(limits,=in values), the handler (parameter with a space, both forms,qomitted, 400s), andsearch_artifacts(passesprop:on, refuses malformed and an 11th filter before searching).Also
propparameter,qandchecksumdescriptions), regenerated client, reference docs andopenapi.json.gz;docs/integrations/api.md,docs/integrations/mcp.md,docs/repositories/properties.md.oa uploadcontent-type note of fix(cli): send the content type of raw files in oa upload #460. That one sits under 0.23.0 on main, but fix(cli): send the content type of raw files in oa upload #460 merged after the 0.23.0 release commit (chore(release): 0.23.0 #458), so I moved it.Checked locally (macOS, Postgres 18):
make check,cmd/docgen -check,bun run typecheck, the unit suite with-race, the slim suite,go test -tags integration ./internal/search/, and the migration tests.🤖 Generated with Claude Code