-
Notifications
You must be signed in to change notification settings - Fork 13
feat: multi nodes #47
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
Draft
haydenhoang
wants to merge
11
commits into
typesense:main
Choose a base branch
from
haydenhoang:multi_nodes_v2
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.
Draft
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
This commit introduces a comprehensive and robust implementation for handling complex document structures within the `#[derive(Typesense)]` macro, enabling powerful schema generation directly from Rust structs. The macro now supports the full range of advanced indexing strategies offered by Typesense, including automatic object indexing, field flattening with prefix control, and patterns for manual flattening. ### Key Features & Implementation Details - **Automatic Object Indexing:** - A field containing a nested struct that also derives `Document` is now automatically mapped to a Typesense `object` (or `object[]` for `Vec<T>`). - This feature requires `#[typesense(enable_nested_fields = true)]` on the parent collection, which the macro now supports. - **Automatic Field Flattening with `#[typesense(flatten)]`:** - A field marked `#[typesense(flatten)]` has its sub-fields expanded into the parent schema using dot-notation. - By default, the Rust field's name is used as the prefix for all sub-fields (e.g., `details: ProductDetails` results in schema fields like `details.part_number`). - **Prefix Override for Flattening:** - The `flatten` attribute can be combined with `rename` to provide a custom prefix for the flattened fields. - Usage: `#[typesense(flatten, rename = "custom_prefix")]` - This provides powerful schema mapping flexibility, allowing the Rust struct's field name to differ from the prefix used in the Typesense schema. - **Manual Flattening Pattern (`skip` + `rename`):** - A new `#[typesense(skip)]` attribute has been introduced to completely exclude a field from the generated Typesense schema. - This enables the powerful pattern of sending both nested and flattened data to Typesense: the nested version can be used for display/deserialization, while a separate set of flattened fields is used for indexing. This is achieved by: 1. Marking the nested struct field (e.g., `details: Details`) with `#[typesense(skip)]`. 2. Adding corresponding top-level fields to the Rust struct, marked with `#[typesense(rename = "details.field_name")]`. - **Ergonomic Boolean Attributes:** - All boolean attributes (`facet`, `sort`, `index`, `store`, `infix`, `stem`, `optional`, `range_index`) now support shorthand "flag" syntax. - For example, `#[typesense(sort)]` is a valid and recommended equivalent to `#[typesense(sort = true)]`, dramatically improving readability and consistency. - **Robust Error Handling & Validation:** - The macro provides clear, compile-time errors for invalid or ambiguous attribute usage. - It correctly detects and reports duplicate attributes, whether they are in the same `#[typesense(...)]` block or across multiple attributes on the same field. ### Testing - **Comprehensive Integration Test (`derive_integration.rs`):** - A new, full-lifecycle integration test has been added to validate the entire feature set. - The test defines a complex struct using every new attribute and pattern, generates a schema, creates a real collection, and uses the generic client (`collection_of<T>`) to perform and validate a full Create, Read, Update, Delete, and Search lifecycle. - A second integration test was added to specifically validate the manual flattening pattern. - **UI Tests:** - `trybuild` UI tests have been added to verify that the macro produces the correct compile-time errors for invalid attribute combinations, such as duplicate attributes.
…bon; restructure library layout
fccf912
to
3bc15f7
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.
Change Summary
work in progress...
PR Checklist