Enhance fetchEntities with search term permutations and deduplication#9101
Enhance fetchEntities with search term permutations and deduplication#9101vedantlavale wants to merge 1 commit into
Conversation
…mutations and deduplication Signed-off-by: vedantlavale <vedantlavale@gmail.com>
Missing ChangesetsThe following package(s) are changed by this PR but do not have a changeset:
See CONTRIBUTING.md for more information about how to add changesets. Changed Packages
|
There was a problem hiding this comment.
Pull request overview
Improves the wheel-of-names participant lookup by enhancing EntityService.fetchEntities() to support 2-word search term permutations (e.g., “Jane Smith” vs “Smith Jane”) and deduplicate merged results, with accompanying unit tests.
Changes:
- Added permutation search for 2-word queries by issuing catalog queries for both word orders and merging results.
- Added client-side deduplication and sorting of merged entity results.
- Introduced unit tests covering permutation search, deduplication, and pagination behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
workspaces/wheel-of-names/plugins/wheel-of-names/src/components/Participants/Service.ts |
Adds 2-word permutation querying, merges/dedupes/sorts results, and applies client-side paging. |
workspaces/wheel-of-names/plugins/wheel-of-names/src/components/Participants/Service.test.ts |
Adds unit tests for the updated fetchEntities behavior and related regressions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const queryOptions: QueryEntitiesRequest = { | ||
| filter: [{ kind: 'group' }, { kind: 'user' }], | ||
| limit: limit, | ||
| offset: offset, | ||
| limit: limit * 2, | ||
| offset: 0, | ||
| orderFields: { field: 'metadata.name', order: 'asc' }, |
| const items = uniqueItems.slice(start, end); | ||
|
|
||
| const totalItems = uniqueItems.length; | ||
|
|
||
| return { items, totalItems }; |
| const uniqueItems = allItems.filter( | ||
| (item, index, self) => | ||
| item.metadata.uid && | ||
| self.findIndex(i => i.metadata.uid === item.metadata.uid) === index, | ||
| ); |
| const allItems: Entity[] = []; | ||
|
|
||
| for (const term of terms) { | ||
| const options: QueryEntitiesRequest = { | ||
| ...queryOptions, | ||
| }; | ||
| if (term) { | ||
| options.fullTextFilter = { | ||
| term, | ||
| fields: [ | ||
| 'metadata.name', | ||
| 'kind', | ||
| 'spec.profile.displayName', | ||
| 'metadata.title', | ||
| ], | ||
| }; | ||
| } | ||
| const response = await this.catalogApi.queryEntities(options); | ||
| allItems.push(...response.items); | ||
| } | ||
|
|
| expect(mockCatalogApi.queryEntities).toHaveBeenCalledWith({ | ||
| filter: [{ kind: 'group' }, { kind: 'user' }], | ||
| limit: 20, | ||
| offset: 0, | ||
| orderFields: { field: 'metadata.name', order: 'asc' }, | ||
| }); |
|
Can you add a test case for "Leonardo Wilhelm DiCaprio"? This change will not fix the real problem as it's only working for names with two words. A lot of users have longer names. Can't we use the Search API to get better results? |
Fix user search failing for reversed display name order
Issue Summary
The wheel-of-names participant search failed when user names were entered in a different order than the stored
displayName.For example:
displayName: "Jane Smith""Jane Smith"→ worked"Smith Jane"→ no resultsThis happened because the catalog API's
fullTextFilteruses substring matching, so reversed word order would not match the stored display name.Solution
Updated
EntityService.fetchEntities()to support name permutations for 2-word search queries.Changes made:
"first last""last first"This keeps the implementation backward compatible while improving search flexibility for users.
Testing
Added comprehensive unit tests in
Service.test.tscovering:Verified with mock user data including:
displayName: "Jane Smith"Files Changed
src/components/Participants/Service.tssrc/components/Participants/Service.test.tsScreenshots
Screenshots
Search using original name order
Search using reversed name order
Additional Notes
Signed-off-bylineSigned-off-bylineFixes #8472