Skip to content

Fix: Preserve order of searchable attributes when modified #5751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2025

Conversation

ManyTheFish
Copy link
Member

Bug Description

When modifying the searchableAttributes setting through the settings API, the order of attributes was not being preserved. The system would incorrectly detect that no changes had occurred when only the order was modified, causing the update to be skipped.

Example:

  • Set searchableAttributes: ["title", "overview"]
  • Modify to searchableAttributes: ["overview", "title"]
  • The system would not detect this as a change and keep the original order

Root Cause

The bug was in the change detection logic within update_user_defined_searchable_attributes() in crates/milli/src/update/settings.rs. The method was comparing the new user-defined order against the computed searchable_fields instead of the user_defined_searchable_fields.

// BUGGY: Comparing against computed fields
let old_fields = self.index.searchable_fields(self.wtxn)?;
let did_change = new_fields != old_fields;

Since searchable_fields returns computed fields that may have a different order than the user-defined ones, order changes were not being detected.

Fix

Changed the comparison to use user_defined_searchable_fields instead:

// FIXED: Compare against user-defined fields
let old_fields = self.index.user_defined_searchable_fields(self.wtxn)?;
let did_change = old_fields.map(|old| new_fields != old).unwrap_or(true);

This ensures that any change in the user-defined order is properly detected and applied.

@ManyTheFish ManyTheFish changed the base branch from main to release-v1.16.0 July 10, 2025 16:28
@ManyTheFish ManyTheFish added this to the v1.16.0 milestone Jul 10, 2025
@ManyTheFish ManyTheFish added no db change The database didn't change bug Something isn't working as expected labels Jul 10, 2025
@ManyTheFish ManyTheFish marked this pull request as ready for review July 10, 2025 16:28
@ManyTheFish ManyTheFish requested a review from Kerollmops July 10, 2025 16:28
Co-authored-by: Clément Renault <clement@meilisearch.com>
@Kerollmops Kerollmops enabled auto-merge July 15, 2025 09:55
@Kerollmops Kerollmops added this pull request to the merge queue Jul 15, 2025
Merged via the queue into release-v1.16.0 with commit 6f248b7 Jul 15, 2025
11 checks passed
@Kerollmops Kerollmops deleted the fix-searchable-attributes-order branch July 15, 2025 11:24
@meili-bot meili-bot added the v1.16.0 PRs/issues solved in v1.16.0 released on 2025-08-04 label Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected no db change The database didn't change v1.16.0 PRs/issues solved in v1.16.0 released on 2025-08-04
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants