Refactor auth filtering to be more efficient#354
Merged
mbklein merged 1 commit intodeploy/stagingfrom Mar 19, 2026
Merged
Conversation
Add `visibility` query param Update OpenAPI spec
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.

This PR refactors the way auth filters are applied to search queries. Currently, an auth filter is calculated based on what should be excluded, then the entire query (regardless of type) is wrapped in a
{ bool: { must: [query], must_not: [filters] } }structure. (There is a slightly different method for hybrid queries, but it just involves applying the above struct to every query inhybrid.queries[].)This refactor calculates the auth filter based on what should be included, and then applies it depending on the query type:
bool: { must: [query], filter: [filters] }boolqueries, it leaves the existing structure alone and adds the necessary filters tobool.filterneuralqueries, it adds the filters toneural[field].filteras a new bool filterhybridqueries, it applies the above rules to each query inhybrid.queries[].The result is a much more efficient and focused query.
The PR also adds an optional
visibilityquery parameter to all search routes, bothGETandPOST. If present, it will limit the auth filter based on the values provided, but never expand the scope beyond what the user's token allows. For example:["Institution", "Public"]+ Query param:visibility=private,public={ terms: { visibility: ["Public"] } }["Private", "Institution", "Public"]+ Query param:visibility=private,institution={ terms: { visibility: ["Private", "Institution"] } }If the main query also includes visibility constraints, the most restrictive filter will apply.
In addition to increasing efficiency, this will allow us to build simpler queries downstream (DC, MCP) and leave the heavy lifting to the API where it belongs.