Skip to content

fix: return OR results for multiple tags in Drive filter (WPB-27126)#21898

Open
cristianoliveira wants to merge 2 commits into
mainfrom
fix/WPB-27126-fix-tags
Open

fix: return OR results for multiple tags in Drive filter (WPB-27126)#21898
cristianoliveira wants to merge 2 commits into
mainfrom
fix/WPB-27126-fix-tags

Conversation

@cristianoliveira

@cristianoliveira cristianoliveira commented Jul 17, 2026

Copy link
Copy Markdown
Contributor
BugWPB-27126 [Web] Selecting multiple tags returns no results instead of matching files with any selected tag

What

Multi-tag search in the Cells API previously collapsed all selected tags into a single JSON-encoded term (e.g. "sam,bug"), which the backend treated as one literal tag value that no node had so any filter with 2+ tags returned zero results.

This PR emits one Metadata entry per tag with Operation: 'Should' and a raw term, mirroring the iOS client (WireMessaging/Sources/WireMessagingData/WireDrive/NodesAPI/RestAPI.swift:643) and the existing mimeTypes / creatorIds pattern in the same file.

Tag filter construction is extracted into a small module-level helper createTagMetadataFilters with an explicit LookupFilterMetaFilter[] return type so the request literal reads by intent rather than by construction detail.

Why

Restores the OR semantics defined in the PRD: a file matching any of the selected tags is returned.

Behaviour change

  • Multiple tags: previously returned 0; now returns files matching any selected tag.
  • Single tag: the returned files are unchanged. The on-wire shape does change from a single JSON-joined term to a per-tag Should entry with a raw term. Verified against the fulu backend that a single-tag lookup with the new shape returns identical results to the old one.

Demo

Screen.Recording.2026-07-17.at.18.53.04.mov

…r [WPB-27126]

Multi-tag search in the Cells API previously collapsed all selected tags
into a single JSON-encoded term (e.g. "sam,bug"), which the backend
treated as one literal tag value that no node had, so results came back
empty.

Emit one Metadata entry per tag with Operation 'Should' and a raw term,
mirroring the iOS client (WireMessaging RestAPI.swift) and the existing
mimeTypes/creatorIds pattern in the same file. This restores OR
semantics: a file matching any selected tag now appears in results.
Single-tag search is unaffected.

Verified end to end against the fulu backend: two tags on distinct
files return both files.

@screendriver screendriver left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request targets dev, but our development branch is now main. dev is currently 169 commits behind main. Please retarget the pull request to main and update the feature branch from main before continuing the review.

...(tags !== undefined && tags.length > 0
? [{Namespace: USER_META_TAGS_NAMESPACE, Term: this.transformTagsToJson(tags)}]
: []),
...(tags?.map(tag => ({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we extract the metadata-filter construction from this request literal? This expression currently combines optional-value handling, collection mapping, API serialization, query semantics, and a type assertion. Together with the MIME type and creator filters below, the request is becoming difficult to scan.

Named helpers such as createTagMetadataFilters, createMimeTypeMetadataFilters, and createCreatorMetadataFilters would let this request describe what it contains rather than how every filter is constructed. An explicit helper return type should also remove the need for as const.

@cristianoliveira cristianoliveira Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Extracted createTagMetadataFilters as a module-level helper with an explicit LookupFilterMetaFilter[] return type, which also drops the as const.

Kept the mime/creator extraction out of this PR to keep the diff scoped to WPB-27126 (both were untouched by the bugfix and I'd rather not modify unrelated code paths under a fix commit). Happy to open a follow-up cleanup PR that applies the same pattern to createMimeTypeMetadataFilters and createCreatorMetadataFilters, let me know if you'd prefer that as part of this one instead.

expect(result).toEqual(mockResponse);
});

it('filters by multiple tags with Should operation (OR) so any selected tag matches (WPB-27126)', async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does not verify that "any selected tag matches." The API is mocked with an empty response, so it only verifies how the lookup request is serialized.

Either rename this to describe what it actually tests, for example, creates one Should metadata filter for each selected tag, or add an integration/E2E regression test that selects multiple tags and verifies that a file matching either tag is returned.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the description, the old name was promising something the test can't actually see

The OR part I verified against the real backend (fulu) I added a demo in the PR description

Deleted: 'Not',
},
Metadata: [{Namespace: 'usermeta-tags', Term: JSON.stringify(tags.join(','))}],
Metadata: [{Namespace: 'usermeta-tags', Term: 'tag1', Operation: 'Should'}],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request description says single-tag search is unaffected. But the actual request changes from:

{
  Namespace: USER_META_TAGS_NAMESPACE,
  Term: this.transformTagsToJson(tags),
}

to

  Namespace: USER_META_TAGS_NAMESPACE,
  Term: tag,
  Operation: 'Should',
}

That changes both the term representation and the explicit operation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, "unaffected" was too loose. What I meant is that a single-tag search still returns only the tagged files with the given tag (See the demo)

@cristianoliveira
cristianoliveira changed the base branch from dev to main July 17, 2026 15:38
@cristianoliveira

cristianoliveira commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@screendriver I appreciate the early feedback, but as of now this is a Draft PR, I'll take into account the concerns you raised

Address review on PR #21898:
- Extract tag metadata filter construction into a named module-level
  helper with an explicit LookupFilterMetaFilter[] return type, dropping
  the inline as const.
- Rename the multi-tag test to describe what it actually verifies
  (request shape, not backend OR semantics).

Mime/creator filter extraction is deferred to a follow-up so this fix
stays scoped to WPB-27126.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants