-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Search metadata #5926
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
Open
ManyTheFish
wants to merge
8
commits into
main
Choose a base branch
from
search-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Search metadata #5926
+657
−43
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Add SearchMetadata struct with queryUid field (UUID v7) - Add metadata field to SearchResult for /search route - Add metadata field to FederatedSearchResult for /multi-search route - Update perform_search to generate queryUid and set metadata - Update federated search to generate queryUid for each query - Update multi-search non-federated path to include metadata - Fix pattern matching in analytics and other code The metadata field contains: - For /search: single object with queryUid - For /multi-search: array of objects, one per query - For federated search: array of objects, one per query All queryUid values are generated using Uuid::now_v7() for time-ordered uniqueness.
- Add indexUid field to SearchMetadata struct - Update perform_search to include indexUid in metadata - Update federated search to include indexUid for each query The metadata field now contains both queryUid and indexUid: - For /search: single object with queryUid and indexUid - For /multi-search: each result has metadata with both fields - For federated search: array of objects, each with queryUid and indexUid
- Add SearchMetadata struct with queryUid, indexUid, primaryKey, and remote fields - Update SearchResult to include metadata field - Update FederatedSearchResult to include metadata array - Refactor federated search metadata building to maintain query order - Support primary key extraction from both local and remote results - Add remote field to identify remote instance for federated queries - Ensure metadata array matches query order in federated search Features: - queryUid: UUID v7 for each query - indexUid: Index identifier - primaryKey: Primary key field name (null if not available) - remote: Remote instance name (null for local queries) This provides complete traceability for search operations across local and remote instances.
- Add Meili-Include-Metadata header constant - Modify perform_search to conditionally include metadata based on header - Modify perform_federated_search to conditionally include metadata based on header - Update all search routes to check for header and pass include_metadata parameter - Forward Meili-Include-Metadata header to remote requests for federated search - Ensure remote queries include primaryKey metadata when header is present
ad804b6
to
4b66c48
Compare
ManyTheFish
commented
Oct 6, 2025
- Use composite key (indexUid, remote) instead of indexUid only for remote metadata lookup - Prevents collisions when multiple remotes have same indexUid but different primary keys - Ensures each remote query gets correct primaryKey from its specific remote instance
- Replace BTreeMap with HashMap for (remote, index_uid) -> primary_key lookup - Prevents collisions when multiple remotes have same index_uid but different primary keys
b21d1af
to
344ad66
Compare
- Create SearchParams struct to group related parameters - Update perform_search function to use SearchParams instead of 8 individual parameters - Fix clippy warning about too many arguments - Update all callers to use new SearchParams struct
344ad66
to
4f4dc47
Compare
- Add 9 test cases covering single search, multi-search, and federated search - Test metadata header opt-in functionality with case insensitivity - Test header false value handling - Test UUID format validation and consistency - Use insta snapshots for reliable, maintainable test assertions - Fix header parsing to properly handle 'false' values - Add helper methods for testing with custom headers
b02785e
to
a0ef800
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Added opt-in metadata to search responses for query traceability. Metadata is only included when the
Meili-Include-Metadata
header is present, ensuring backward compatibility.API Changes
New Header
Meili-Include-Metadata
true
or1
to activate itNew Response Fields
Single Search (
/indexes/{indexUid}/search
)Multi-Search (
/multi-search
)Federated Search (
/multi-search
with federation)Metadata Fields
queryUid
indexUid
primaryKey
remote
Usage Examples
Basic Search with Metadata
Request:
Response:
Multi-Search with Metadata
Request:
Response:
Federated Search with Metadata
Request:
Response:
Implementation Notes