-
Notifications
You must be signed in to change notification settings - Fork 107
Add dynamic search rules #2171
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
Add dynamic search rules #2171
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8579763
Add dynamic search rules
Strift 2492f8a
Update types
Strift c0b98dc
Check presence of expected fields only
Strift eaf33a1
Rename files
Strift 4b55b1d
Update experimental features
Strift 3c7bf9c
Update experimental features test
Strift 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
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 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 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 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 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 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,60 @@ | ||
| export type SearchRuleListFilterPayload = { | ||
| attributePatterns?: string[] | null; | ||
| active?: boolean | null; | ||
| }; | ||
|
|
||
| export type SearchRuleListPayload = { | ||
| offset?: number; | ||
| limit?: number; | ||
| filter?: SearchRuleListFilterPayload | null; | ||
| }; | ||
|
|
||
| export type SearchRuleSelector = { | ||
| indexUid?: string | null; | ||
| id?: string | null; | ||
| }; | ||
|
|
||
| export type SearchRulePinAction = { | ||
| type: "pin"; | ||
| position: number; | ||
| }; | ||
|
|
||
| export type SearchRuleAction = { | ||
| selector: SearchRuleSelector; | ||
| action: SearchRulePinAction; | ||
| }; | ||
|
|
||
| export type SearchRuleQueryCondition = { | ||
| scope: "query"; | ||
| isEmpty?: boolean | null; | ||
| contains?: string | null; | ||
| }; | ||
|
|
||
| export type SearchRuleTimeCondition = { | ||
| scope: "time"; | ||
| start?: string | null; | ||
| end?: string | null; | ||
| }; | ||
|
|
||
| export type SearchRuleCondition = | ||
| | SearchRuleQueryCondition | ||
| | SearchRuleTimeCondition; | ||
|
|
||
| /** Dynamic search rule object */ | ||
| export type SearchRule = { | ||
| uid: string; | ||
| description?: string | null; | ||
| priority?: number | null; | ||
| active?: boolean; | ||
| conditions?: SearchRuleCondition[]; | ||
| actions: SearchRuleAction[]; | ||
| }; | ||
|
|
||
| /** Partial update payload for a dynamic search rule */ | ||
| export type SearchRuleUpdatePayload = { | ||
| description?: string | null; | ||
| priority?: number | null; | ||
| active?: boolean | null; | ||
| conditions?: SearchRuleCondition[] | null; | ||
| actions?: SearchRuleAction[] | null; | ||
| }; |
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 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,83 @@ | ||
| import { afterAll, beforeAll, describe, expect, it } from "vitest"; | ||
| import { getClient } from "./utils/meilisearch-test-utils.js"; | ||
| import { Meilisearch, type SearchRuleUpdatePayload } from "../src/index.js"; | ||
|
|
||
| let adminClient: Meilisearch; | ||
| let masterClient: Meilisearch; | ||
|
|
||
| const SEARCH_RULE_UID = "movie-rule"; | ||
| const SEARCH_RULE_PATCH: SearchRuleUpdatePayload = { | ||
| actions: [ | ||
| { | ||
| selector: { | ||
| indexUid: "movies", | ||
| id: "1", | ||
| }, | ||
| action: { | ||
| type: "pin", | ||
| position: 1, | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| beforeAll(async () => { | ||
| adminClient = await getClient("Admin"); | ||
| masterClient = await getClient("Master"); | ||
| const dynamicSearchRulesFeature = { | ||
| dynamicSearchRules: true, | ||
| } as unknown as Parameters<Meilisearch["updateExperimentalFeatures"]>[0]; | ||
| await masterClient.updateExperimentalFeatures(dynamicSearchRulesFeature); | ||
|
Strift marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| const response = await masterClient.getDynamicSearchRules(); | ||
| for (const rule of response.results) { | ||
| await masterClient.deleteDynamicSearchRule(rule.uid); | ||
| } | ||
| }); | ||
|
|
||
| describe("dynamic search rules", () => { | ||
| it("can list dynamic search rules", async () => { | ||
| const response = await adminClient.getDynamicSearchRules({ | ||
| offset: 0, | ||
| limit: 20, | ||
| filter: { attributePatterns: [SEARCH_RULE_UID] }, | ||
| }); | ||
| expect(response).toHaveProperty("results"); | ||
| expect(response.results).toBeInstanceOf(Array); | ||
| }); | ||
|
|
||
| it("can create or update a dynamic search rule with patch payload", async () => { | ||
| const response = await adminClient.updateDynamicSearchRule( | ||
| SEARCH_RULE_UID, | ||
| SEARCH_RULE_PATCH, | ||
| ); | ||
|
|
||
| expect(response).toHaveProperty("uid", SEARCH_RULE_UID); | ||
| expect(response).toHaveProperty("actions", SEARCH_RULE_PATCH.actions); | ||
| }); | ||
|
|
||
| it("can fetch a dynamic search rule", async () => { | ||
| await adminClient.updateDynamicSearchRule( | ||
| SEARCH_RULE_UID, | ||
| SEARCH_RULE_PATCH, | ||
| ); | ||
|
|
||
| const response = await adminClient.getDynamicSearchRule(SEARCH_RULE_UID); | ||
|
|
||
| expect(response).toHaveProperty("uid", SEARCH_RULE_UID); | ||
| expect(response).toHaveProperty("actions", SEARCH_RULE_PATCH.actions); | ||
| }); | ||
|
|
||
| it("can delete a dynamic search rule", async () => { | ||
| await adminClient.updateDynamicSearchRule( | ||
| SEARCH_RULE_UID, | ||
| SEARCH_RULE_PATCH, | ||
| ); | ||
|
|
||
| const response = await adminClient.deleteDynamicSearchRule(SEARCH_RULE_UID); | ||
|
|
||
| expect(response).toBeUndefined(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.