-
Notifications
You must be signed in to change notification settings - Fork 8
Add a new page for advanced queries #140
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| --- | ||
| sidebar_position: 5 | ||
| title: Advanced Query Language | ||
| --- | ||
|
|
||
| # Advanced Query Language (DSL) | ||
|
|
||
| The Advanced Query feature uses a Domain-Specific Language (DSL) to create dynamic, personalized filters for articles and recommendations. This powerful system allows you to build complex logic using variables, primitives, functions, and conditional statements to deliver relevant content based on user data and context. | ||
|
|
||
| ## Key Variables | ||
|
|
||
| These built-in variables provide essential context for your queries: | ||
|
|
||
| - **`EMPTY`**: Represents an empty result set. Use when you want to return no results under certain conditions. | ||
|
|
||
| **Example:** `unread(articles) if user.age >= 18 else EMPTY` | ||
|
|
||
| Returns unread articles for users 18+, otherwise returns nothing. | ||
|
|
||
| - **`NOW`**: Current date and time timestamp. | ||
|
|
||
| - **`TODAY`**: Current date (without time component). | ||
|
|
||
| - **`articles`**: Collection of all available articles. Use this for article-specific queries like `unread(articles)`, `limit(articles, 5)`, or `filter(articles, tags="HR")`. | ||
|
|
||
| - **`recommendations`**: Collection of all available recommendations. Use this for recommendation-specific queries like `limit(recommendations, 3)`, or `filter(recommendations, tags="exercise")`. | ||
|
igori-huma marked this conversation as resolved.
|
||
|
|
||
| ## Data Primitives | ||
|
|
||
| Access user health data through the `data` object structure: | ||
|
|
||
| ### Basic Metrics | ||
| - **`data.<primitive>`**: Access any recorded health metric (HeartRate, Weight, Temperature, etc.) | ||
| - **`data.<primitive>.value`**: The actual recorded value (number or decimal) | ||
| - **`data.<primitive>.flags`**: Severity level indicators with three levels: | ||
| - `flags.gray`: Normal range | ||
| - `flags.amber`: Warning level | ||
| - `flags.red`: Critical level | ||
|
|
||
| ### Complex Metrics | ||
| For metrics with multiple values: | ||
| - `data.BloodPressure.systolicValue` | ||
| - `data.BloodPressure.diastolicValue` | ||
|
|
||
| ## Functions | ||
|
|
||
| ### Core Functions | ||
|
|
||
| - **`limit(collection: array, count: int)`** | ||
|
|
||
| Restricts the number of returned items from the specified collection. | ||
|
|
||
| **Examples:** | ||
| - `limit(unread(articles), 2)` - Shows maximum 2 unread articles | ||
| - `limit(recommendations, 3)` - Shows maximum 3 recommendations | ||
|
|
||
| - **`unread(articles: array)`** | ||
|
|
||
| Filters to show only unread articles. | ||
|
|
||
| **Example:** | ||
| ``` | ||
| unread(articles) | ||
| ``` | ||
| Returns all unread articles. | ||
|
|
||
| - **`filter(collection: array, tags: string)`** | ||
|
|
||
| Filters items by specific tags from the specified collection. | ||
|
|
||
| **Examples:** | ||
| - `filter(articles, tags="HR")` - Shows articles tagged with "HR" | ||
| - `filter(recommendations, tags="exercise")` - Shows recommendations tagged with "exercise" | ||
|
|
||
| - **`random(collection: array, count: int)`** | ||
|
|
||
| Returns a random selection from the specified collection. | ||
|
|
||
| **Examples:** | ||
| - `random(articles, 3)` - Shows 3 randomly selected articles | ||
| - `random(recommendations, 2)` - Shows 2 randomly selected recommendations | ||
|
|
||
| ## Conditional Logic | ||
|
|
||
| The DSL uses Python-style syntax for building complex conditions: | ||
|
|
||
| ### If/else Statements | ||
|
|
||
| **Syntax:** `<result_if_true> if <condition> else <result_if_false>` | ||
|
|
||
| **Example:** | ||
| ``` | ||
| filter(articles, tags="HR") if data.HeartRate.flags.red > 0 else limit(unread(articles), 2) | ||
| ``` | ||
| Shows heart rate articles if the last reading is critical, otherwise shows 2 unread articles. | ||
|
|
||
| ### Logical Operators | ||
|
|
||
| - **`and`**: Both conditions must be true | ||
| - **`or`**: Either condition can be true | ||
|
|
||
| **Example:** | ||
| ``` | ||
| unread(articles) if data.HeartRate.flags.amber or data.HeartRate.flags.red else random(recommendations, 2) | ||
| ``` | ||
| Returns unread articles if heart rate is in warning or critical range, otherwise shows 2 random recommendations. | ||
|
|
||
| ### Combination Operator | ||
|
|
||
| - **`+`**: Combines multiple article sets | ||
|
|
||
| **Example:** | ||
| ``` | ||
| filter(articles, tags="HR") + filter(recommendations, tags="sport") | ||
| ``` | ||
| Shows all articles tagged with "HR" plus all recommendations tagged with "sport". | ||
|
|
||
| ## Practical Examples | ||
|
|
||
| ### Basic Filtering | ||
| ``` | ||
| limit(unread(articles), 5) | ||
| limit(recommendations, 3) | ||
| ``` | ||
| Show 5 most recent unread articles, or 3 most recent recommendations. | ||
|
|
||
| ### Health-Based Filtering | ||
| ``` | ||
| filter(articles, tags="diabetes") if data.BloodSugar.flags.red else unread(articles) | ||
| ``` | ||
| Show diabetes articles if blood sugar is critical, otherwise show all unread articles. | ||
|
|
||
| ### Complex Conditions | ||
| ``` | ||
| filter(articles, tags="exercise") if data.HeartRate.value > 100 and data.Weight.flags.amber else limit(articles, 3) | ||
| ``` | ||
| Show exercise articles if heart rate is elevated and weight is in warning range, otherwise show 3 articles. | ||
|
|
||
| ### Combining Collections | ||
| ``` | ||
| filter(articles, tags="nutrition") + filter(recommendations, tags="diet") | ||
| ``` | ||
| Show nutrition articles combined with diet recommendations. | ||
|
|
||
| --- | ||
|
|
||
| This guide provides a comprehensive understanding of how to leverage the Advanced Query feature using DSL. Use these tools to create personalized, context-aware queries that can target either articles or recommendations based on user health data and preferences. | ||
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 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.
Uh oh!
There was an error while loading. Please reload this page.