Skip to content

Bug: SystemTags search missing tags with low IDs due to array key collision #57730

@Tash1ro

Description

@Tash1ro

Bug description

In the Unified Search, when searching for tags, some tags are not displayed in the "All tagged X ..." results even though files with those tags are found.

Steps to reproduce

  1. Create several tags with names containing the same word, e.g.:

    • "Beautiful girl" - this one has a low ID like 2
    • "Girl in dress" - higher ID like 23
    • "Girl in shorts" - higher ID like 21
  2. Assign these tags to some files

  3. Use Unified Search to search for "girl"

  4. Observe that:

    • Files with all tags are found correctly
    • "All tagged Girl in dress ..." appears
    • "All tagged Girl in shorts ..." appears
    • "All tagged Beautiful girl ..." is MISSING (the tag with low ID)

Expected behavior

All matching tags should appear in the "All tagged X ..." results list.

Actual behavior

Tags with low IDs (like 2, 3, etc.) that match file result array indices are silently dropped.

Root cause

In apps/systemtags/lib/Search/TagSearchProvider.php, line 137-138:

}, $searchResults)                                                                                                                                                                                                                
+ $tagResults,                                                                                                                                                                                                                    

The + operator in PHP preserves keys from the first array. The $tagResults array has tag IDs as keys (e.g., [2 => ..., 21 => ..., 23 => ...]), while array_map() on $searchResults creates sequential indices [0, 1, 2, 3, ...].

When arrays are merged with +, if a key exists in the first array, the value from the second array is ignored. So tag with ID=2 collides with file result at index 2 and gets dropped.

Proposed fix

Replace:
array_map(..., $searchResults) + $tagResults,

With:
array_merge(array_values(array_map(..., $searchResults)), array_values($tagResults)),

This ensures all elements are included regardless of their original keys.

Environment

  • Nextcloud version: 31.0.9
  • PHP version: 8.x

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions