discourse/plugins/chat/assets/stylesheets/common
Joffrey JAFFEUX 7ecb945ec4
FEATURE: Add full-text search for chat messages (#34704)
## Overview

This PR introduces comprehensive search functionality for chat messages,
enabling users to search through their chat history both globally across
all accessible channels and within specific channels.

### Search Capabilities

**All-Channel Search**: When no channel is specified, users can search
across all channels they have access to. The search respects channel
permissions through `ChannelFetcher.all_secured_channel_ids`, ensuring
users only see results from channels they can view.

**Per-Channel Search**: Users can scope their search to a specific
channel by providing a `channel_id` parameter, useful for finding
messages within a particular conversation context.

**Search Features**:
- Full-text search using PostgreSQL's tsvector/tsquery
- Advanced filters: `@username` to filter by author, `#channel` to
filter by channel slug
- Sort options: relevance (default) or latest
- Pagination support
- Search data weighted by relevance

## Site Setting: `chat_search_enabled`

This feature is gated behind the `chat_search_enabled` site setting,
which is currently:
- **Default**: `false`
- **Hidden**: `true`
- **Client-accessible**: `true`

### Deployment Strategy

Due to the need for chat messages to be indexed before search becomes
useful, we're implementing a two-phase deployment:

**Phase 1 (Initial Merge)**:
- `chat_search_enabled` remains `false` and hidden
- The `register_search_index` uses default (true) instead of `chat_search_enabled` value
- This allows the reindexing infrastructure to begin indexing existing
chat messages even if we don't show the UI yet

**Wait Period**:
- Wait at least one week after Phase 1 deployment
- `Jobs::ReindexSearch` runs every 2 hours and will progressively index
all chat messages
- This ensures most sites have a significant part of their chat history indexed

**Phase 2 (Follow-up Merge)**:
- Set `chat_search_enabled` default to `true` and unhide it
- Update the `register_search_index` enabled proc uses the default
(true) instead of using the `chat_search_enabled` setting
- Users can now access search with pre-indexed data

**Rationale**: Without this phased approach, users would see the search
UI immediately but receive no results until the reindexing job runs,
creating a confusing experience. By pre-indexing while the UI is hidden,
we ensure search works immediately when enabled.

## New Plugin API: `register_search_index`

This PR introduces a new plugin API that allows plugins to register
custom search indexes that integrate seamlessly with Discourse's search
infrastructure.

### API Signature

```ruby
register_search_index(
  model_class:,              # The ActiveRecord model to index
  search_data_class:,        # The model for storing search data
  index_version:,            # Version number for re-indexing
  search_data:,              # Proc that returns weighted search data
  load_unindexed_record_ids:,# Proc that finds records needing indexing
  enabled:                   # Optional proc to enable/disable (default: -> { true })
)
```

### How It Works

**Integration with SearchIndexer**: When `SearchIndexer.index(obj)` is
called, it checks registered search handlers for the object's type. If a
handler matches, it:
1. Calls the `search_data` proc with the object and an `IndexerHelper`
instance
2. Receives weighted search data (`:a_weight`, `:b_weight`, `:c_weight`,
`:d_weight`)
3. Updates the corresponding search data table with PostgreSQL's
tsvector

**Integration with Jobs::ReindexSearch**: The scheduled job (runs every
2 hours) calls `rebuild_registered_search_handlers`, which:
1. Iterates through all registered search handlers
2. Skips handlers where `enabled` proc returns `false`
3. Calls `load_unindexed_record_ids` to find records needing indexing
4. Indexes up to `limit` records per handler (default: 10,000)

### Chat Implementation Example

```ruby
register_search_index(
  model_class: Chat::Message,
  search_data_class: Chat::MessageSearchData,
  index_version: 1,
  search_data: proc { |message, indexer_helper|
    {
      a_weight: message.message,
      d_weight: indexer_helper.scrub_html(message.cooked)[0..600_000]
    }
  },
  load_unindexed_record_ids: proc { |limit:, index_version:|
    Chat::Message
      .joins("LEFT JOIN chat_message_search_data ON chat_message_id = chat_messages.id")
      .where(
        "chat_message_search_data.locale IS NULL OR 
         chat_message_search_data.locale != ? OR 
         chat_message_search_data.version != ?",
        SiteSetting.default_locale,
        index_version
      )
      .order("chat_messages.id ASC")
      .limit(limit)
      .pluck(:id)
  }
)
```

Co-authored-by: Martin Brennan <mjrbrennan@gmail.com>
Co-authored-by: Loïc Guitaut <5648+Flink@users.noreply.github.com>
2025-10-22 11:30:35 +02:00
..
base-common.scss UX: adds a start new dm link when no dms present (#34820) 2025-09-17 08:18:31 +02:00
chat-audio-upload.scss FIX: prevents audio container to overflow container (#25012) 2023-12-22 09:38:21 +01:00
chat-browse.scss DEV: Replace all @breakpoint with @viewport.* (#32649) 2025-05-12 12:52:45 +01:00
chat-channel-card.scss DEV: Introduce stylelint (#29852) 2025-01-20 15:27:42 +00:00
chat-channel-filter-bar.scss FEATURE: Add full-text search for chat messages (#34704) 2025-10-22 11:30:35 +02:00
chat-channel-icon.scss DEV: Update linting (#32836) 2025-05-21 12:02:52 +02:00
chat-channel-info.scss UX: chat > channel info: show member count on tab (#25439) 2024-01-26 12:10:56 +01:00
chat-channel-members.scss UX: Content border color (#33908) 2025-07-28 16:17:06 -05:00
chat-channel-name.scss DEV: Fix mixed-decls sass deprecations in plugins (#31356) 2025-02-18 20:04:51 +01:00
chat-channel-preview-card.scss FIX: dont allow channel non-members to write messages in threads (#31697) 2025-03-07 15:50:30 +04:00
chat-channel-row.scss DEV: Update lint-configs and auto-fix issues (#31485) 2025-02-24 23:32:31 +01:00
chat-channel-settings.scss DEV: Update lint-configs and auto-fix issues (#31485) 2025-02-24 23:32:31 +01:00
chat-channel-title.scss DEV: Update linting (#32836) 2025-05-21 12:02:52 +02:00
chat-channel.scss DEV: Update lint-configs and auto-fix issues (#31485) 2025-02-24 23:32:31 +01:00
chat-composer-button.scss DEV: Replace all @breakpoint with @viewport.* (#32649) 2025-05-12 12:52:45 +01:00
chat-composer-dropdown.scss DEV: Introduce stylelint (#29852) 2025-01-20 15:27:42 +00:00
chat-composer-separator.scss Revert "UX: chat composer (#23267)" (#23273) 2023-08-25 13:49:41 -05:00
chat-composer-upload.scss DEV: Update linting (#32836) 2025-05-21 12:02:52 +02:00
chat-composer-uploads.scss UX: align navbar and composer uploads (#24970) 2023-12-19 15:41:51 +01:00
chat-composer.scss DEV: Add Chat page variables (#33936) 2025-07-29 11:22:50 -05:00
chat-drawer-routes.scss FEATURE: allows browse page in chat drawer (#27919) 2024-07-16 12:34:37 +02:00
chat-drawer.scss FEATURE: Add full-text search for chat messages (#34704) 2025-10-22 11:30:35 +02:00
chat-footer.scss UX: Content border color (#33908) 2025-07-28 16:17:06 -05:00
chat-form.scss UX: Content border color (#33908) 2025-07-28 16:17:06 -05:00
chat-height-mixin.scss UX: Do not let composer affect chat window height (#32423) 2025-04-24 09:32:28 -05:00
chat-index.scss REFACTOR: consolidate empty states, add invite variant (#33455) 2025-07-09 12:34:04 -04:00
chat-mention-warnings.scss DEV: implements <Chat::Navbar /> (#24917) 2023-12-18 17:49:58 +01:00
chat-message-actions.scss UX: Chat more message actions adjustments (#32404) 2025-04-22 16:36:21 -05:00
chat-message-blocks.scss DEV: adds blocks support to chat messages (#29782) 2024-11-19 07:07:58 +01:00
chat-message-collapser.scss FIX: Resize chat collapser when using small width drawer (#21017) 2023-04-08 10:43:17 -03:00
chat-message-creator.scss UX: fix cmd-k bottom padding (#34440) 2025-08-20 16:45:39 +02:00
chat-message-error.scss REFACTOR: <ChatMessage> component (#22172) 2023-06-19 09:50:54 +02:00
chat-message-images.scss DEV: Merge duplicated css (#31167) 2025-02-05 18:42:55 +01:00
chat-message-info.scss DEV: Update lint-configs and auto-fix issues (#31485) 2025-02-24 23:32:31 +01:00
chat-message-left-gutter.scss DEV: Fix random typos (#21638) 2023-05-18 15:34:46 +02:00
chat-message-search-entry.scss FEATURE: Add full-text search for chat messages (#34704) 2025-10-22 11:30:35 +02:00
chat-message-separator.scss DEV: Add Chat page variables (#33936) 2025-07-29 11:22:50 -05:00
chat-message-text.scss UX: removes blinking indicator while streaming message (#27131) 2024-05-22 13:48:44 +02:00
chat-message-thread-indicator.scss FIX: improves linking of thread messages (#26095) 2024-03-08 09:09:42 +01:00
chat-message.scss FEATURE: Add full-text search for chat messages (#34704) 2025-10-22 11:30:35 +02:00
chat-messages-scroller.scss DEV: Update lint-configs and autofix issues (#31620) 2025-03-05 01:20:16 +01:00
chat-modal-archive-channel.scss DEV: makes chat modals use the new <DModal /> component (#22495) 2023-07-10 13:43:33 +02:00
chat-modal-channel-summary.scss DEV: makes chat modals use the new <DModal /> component (#22495) 2023-07-10 13:43:33 +02:00
chat-modal-create-channel.scss DEV: Introduce stylelint (#29852) 2025-01-20 15:27:42 +00:00
chat-modal-edit-channel-description.scss DEV: makes chat modals use the new <DModal /> component (#22495) 2023-07-10 13:43:33 +02:00
chat-modal-move-message-to-channel.scss DEV: Introduce stylelint (#29852) 2025-01-20 15:27:42 +00:00
chat-modal-new-message.scss UX: fix cmd-k bottom padding (#34440) 2025-08-20 16:45:39 +02:00
chat-navbar.scss DEV: Add Chat page variables (#33936) 2025-07-29 11:22:50 -05:00
chat-notices.scss DEV: Merge duplicated css (#31167) 2025-02-05 18:42:55 +01:00
chat-onebox.scss FIX: Allow oneboxes with no description (#31518) 2025-02-26 13:16:51 +10:00
chat-reply.scss DEV: Merge duplicated css (#31167) 2025-02-05 18:42:55 +01:00
chat-replying-indicator.scss DEV: replace zero width space character in chat typing indicator (#31675) 2025-03-06 15:53:50 -05:00
chat-scroll-to-bottom.scss FIX: removes shift which is not necessary anymore (#32979) 2025-05-28 20:07:05 +02:00
chat-search.scss FEATURE: Add full-text search for chat messages (#34704) 2025-10-22 11:30:35 +02:00
chat-section.scss UX: Content border color (#33908) 2025-07-28 16:17:06 -05:00
chat-selection-manager.scss UX: Content border color (#33908) 2025-07-28 16:17:06 -05:00
chat-side-panel-resizer.scss FIX: do not store 0 has min width for thead panel (#30818) 2025-01-16 16:03:35 +01:00
chat-skeleton.scss DEV: Update linting (#32836) 2025-05-21 12:02:52 +02:00
chat-thread-header.scss UX: Content border color (#33908) 2025-07-28 16:17:06 -05:00
chat-thread-heading.scss FIX: word break long continuous thread titles (#30007) 2024-11-30 01:07:39 +01:00
chat-thread-list-header.scss UX: Content border color (#33908) 2025-07-28 16:17:06 -05:00
chat-thread-list-item.scss UX: Content border color (#33908) 2025-07-28 16:17:06 -05:00
chat-thread-participants.scss DEV: Introduce stylelint (#29852) 2025-01-20 15:27:42 +00:00
chat-thread-title.scss UX: allow users to click thread title to open it (#24816) 2023-12-11 13:54:00 +01:00
chat-thread-unread-indicator.scss DEV: Fix mixed-decls sass deprecations in plugins (#31356) 2025-02-18 20:04:51 +01:00
chat-thread.scss DEV: Update lint-configs and auto-fix issues (#31485) 2025-02-24 23:32:31 +01:00
chat-threads-list.scss DEV: Update lint-configs and auto-fix issues (#31485) 2025-02-24 23:32:31 +01:00
chat-transcript.scss UX: Content border color (#33908) 2025-07-28 16:17:06 -05:00
chat-unread-indicator.scss DEV: Fix mixed-decls sass deprecations in plugins (#31356) 2025-02-18 20:04:51 +01:00
chat-upload-drop-zone.scss DEV: Update linting (#32836) 2025-05-21 12:02:52 +02:00
chat-user-avatar.scss DEV: Update lint-configs and autofix issues (#31620) 2025-03-05 01:20:16 +01:00
chat-user-threads.scss UX: Content border color (#33908) 2025-07-28 16:17:06 -05:00
core-extensions.scss UX: show chat in plugin list (#33735) 2025-07-21 12:01:42 -04:00
direct-message-creator.scss UX: Content border color (#33908) 2025-07-28 16:17:06 -05:00
incoming-chat-webhooks.scss DEV: Introduce stylelint (#29852) 2025-01-20 15:27:42 +00:00
index.scss FEATURE: Add full-text search for chat messages (#34704) 2025-10-22 11:30:35 +02:00
reviewable-chat-message.scss