Skip to content

fix(search): extend messages text index to include attachment fields#40874

Open
rish106-hub wants to merge 3 commits into
RocketChat:developfrom
rish106-hub:fix/issue-2938-search-attachment-fields
Open

fix(search): extend messages text index to include attachment fields#40874
rish106-hub wants to merge 3 commits into
RocketChat:developfrom
rish106-hub:fix/issue-2938-search-attachment-fields

Conversation

@rish106-hub

@rish106-hub rish106-hub commented Jun 10, 2026

Copy link
Copy Markdown

Proposed changes

Renaming a room or using integrations to post with attachments — the attachment content (title, description, text, pretext, author_name) was never included in MongoDB's text index on the messages collection. Only msg (message body) was indexed, so searching for terms that appeared only in attachments returned no results.

Fix: Extend the text index to cover attachment text fields. On startup, ensureMessagesTextIndex detects the old msg-only index, drops it, and rebuilds with the new shape automatically.

Issue

Closes #2938

Steps to test or reproduce

  1. Send a message via an integration (or REST API) with an attachment that has a title or text field containing a unique search term — but leave the message body empty or with different text
  2. Use the search bar to search for the term
  3. Before fix: no results
  4. After fix: message with attachment appears in results

Further comments

  • Index rebuild happens automatically on server startup — may take several minutes on large databases (existing startup log warns about this)
  • Both default and room-scoped (USE_ROOM_SEARCH_INDEX=true) index shapes are updated
  • classifyTextIndex updated to match new weight set so stale old index is detected and replaced

Summary by CodeRabbit

  • Bug Fixes
    • Message search now includes attachment content (text, title, description, pretext, and author name), so searches return results contained in attachments as well as message body. This improves relevance and discoverability of attachment content across global and room searches.

@rish106-hub rish106-hub requested a review from a team as a code owner June 10, 2026 08:37
@dionisio-bot

dionisio-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0530727

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b4e70f13-38e1-4103-9cc2-556665da0414

📥 Commits

Reviewing files that changed from the base of the PR and between e835e4e and 0530727.

📒 Files selected for processing (1)
  • apps/meteor/server/startup/ensureMessagesTextIndex.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/server/startup/ensureMessagesTextIndex.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer

Walkthrough

This PR extends MongoDB text indexing for message search to include attachment-related text fields (text, title, description, pretext, author_name) beyond the message body, enabling search results to match content within post attachments. The configuration, validation logic, and index creation are updated together with release notes.

Changes

Message Search Index Expansion

Layer / File(s) Summary
Attachment field configuration and index validation
apps/meteor/server/startup/ensureMessagesTextIndex.ts
ATTACHMENT_TEXT_FIELDS constant and TEXT_INDEX_FIELDS map define which attachment properties are searchable; classifyTextIndex validates existing indexes by checking exact expected weight keys instead of only checking msg presence.
Index creation with expanded fields
apps/meteor/server/startup/ensureMessagesTextIndex.ts
createIndex call now uses the expanded TEXT_INDEX_FIELDS (including attachments.text, attachments.title, attachments.description, attachments.pretext, attachments.author_name) plus optional rid: 1 scope and uses messages_text_room / messages_text index names.
Release notes
.changeset/fix-search-attachment-fields.md
Changeset entry declares a @rocket.chat/meteor patch documenting the fix to include attachment text fields in message search.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • RocketChat/Rocket.Chat#40397: Modifies ensureMessagesTextIndex.ts with an earlier change to index shape and room-scoped setup, providing related context for how the text index is structured and validated.

Suggested labels

type: bug

Suggested reviewers

  • ggazzo
  • KevLehman
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: extending the MongoDB text index on messages to include attachment fields for search functionality.
Linked Issues check ✅ Passed The PR fully addresses issue #2938 by extending the text index to include attachment fields (title, description, text, pretext, author_name), enabling search on attachment content.
Out of Scope Changes check ✅ Passed All changes are directly related to the objective of extending the text index to cover attachment fields and ensuring automatic index migration on startup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • ISSUE-2938: Request failed with status code 401

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rish106-hub rish106-hub left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@rish106-hub rish106-hub left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@rish106-hub

Copy link
Copy Markdown
Author

Hi @ggazzo and @KevLehman , the PR is ready for review. All automated checks (cubic, CodeRabbit, CLA) are passing with no issues flagged. Would appreciate a review when you get a chance. Happy to make any changes if needed!

Auto-generated names for large text indexes can exceed MongoDB's
127-byte limit on older versions/FCV, causing startup failure.
Explicit short names prevent this.
@coderabbitai coderabbitai Bot removed the type: bug label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search not working on post attachments

1 participant