feat(contextCenter): support sortBy/sortOrder on page hierarchy search - #31625
feat(contextCenter): support sortBy/sortOrder on page hierarchy search#31625sonika-shah wants to merge 7 commits into
Conversation
Adds sortBy/sortOrder query params to GET /v1/contextCenter/pages/search/hierarchy so newly created articles/quick links can surface at the top of the left-tree hierarchy. Threads a SearchSortFilter from the resource through KnowledgePageRepository, the SearchClient interface, and the ES/OS clients. - Default sort is updatedAt desc (newest first); sortBy accepts name/createdAt/ updatedAt, sortOrder accepts asc/desc, invalid values return 400 (reuses the existing resolveSortField/resolveSortOrder validators). - fullyQualifiedName (keyword, unique per page) is always appended as a stable tiebreaker so from/size pagination cannot miss or duplicate hits when the primary sort field is non-unique.
limit=1000000 on the search hierarchy path becomes the ES/OpenSearch query size, which exceeds the default index.max_result_window (10000) and makes the shard fail with search_phase_execution_exception (500). The three test pages fit comfortably in a small window, so query with limit=1000.
Addresses PR review: - Drop 'createdAt' from the hierarchy sortBy allowableValues/description. resolveSortField maps createdAt -> the updatedAt field (the index has no createdAt), so advertising it was misleading. Advertise name + updatedAt only; the updatedAt-desc default already surfaces newly-created pages at the top. - Replace the raw "fullyQualifiedName"/"desc" literals in the ES/OS hierarchy sort helper with Entity.FIELD_FULLY_QUALIFIED_NAME and a SORT_ORDER_DESC constant.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
The left-tree hierarchy is fetched once and only refreshed on create / quick-link edit, so editing an article's content in place did not reorder the tree — the edited page stayed put even though the backend now returns updatedAt-desc order (the card list, which refetches, did move it to the top). Refresh the tree whenever the currently-open article's updatedAt bumps, so an edit moves it to the top of its branch without a manual reload. Guarded to the same article's updatedAt increasing, so navigating between pages only records a baseline.
|
The previous updatedAt watcher on the parent page.data never fired: the content and displayName autosaves in KnowledgePageDetailComponent update only local state (description/displayName/version) and never push a fresh updatedAt up via onPageChange, so the parent never saw a change and the left-tree stayed frozen. Trigger the tree refresh where the save actually completes instead: add an onArticleSaved callback, wired from ContextCenterArticlesPage to knowledgePagesHierarchyRef.fetchKnowledgePageHierarchy(true), and invoke it on successful content and displayName saves. The edited article now re-sorts to the top of its branch (updatedAt desc) without a manual reload. Verified live on OpenSearch: editing a mid-tree article moves it to the top and issues a fresh /search/hierarchy fetch.
updatePage (tags/owners/reviewers/domains) and updatePageTag also patch the page and advance updatedAt, so they must trigger the tree re-sort too — otherwise editing those fields wouldn't move the article to the top. Call onArticleSaved() after the successful patch in both, matching the content/displayName paths.
Knocks down the sonarjs/no-duplicate-string warning near the changed code: 'label.article-plural' was repeated 4x; extracted to ARTICLE_PLURAL_LABEL.
Code Review ✅ Approved 1 resolved / 1 findingsAdds validated sortBy and sortOrder query parameters to the Context Center page hierarchy search, supporting deterministic sorting and reliable tree refreshes. No issues found. ✅ 1 resolved✅ Quality: onArticleSaved not fired on tag/owner/domain saves
OptionsDisplay: compact → Showing less information. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |



What
Adds
sortBy/sortOrderquery params toGET /v1/contextCenter/pages/search/hierarchyso the Context Center left-tree can control ordering — e.g. a newly created article or quick link surfaces at the top instead of the bottom.Fixes open-metadata/openmetadata-collate#4781(item 1 — article hierarchy sorting).How
Threads a
SearchSortFilterfrom the resource throughKnowledgePageRepository→ theSearchClientinterface → the ES/OS client implementations:KnowledgePageResource—listHierarchyWithSearchgainssortBy(name/updatedAt) andsortOrder(asc/desc). Reuses the existingresolveSortField/resolveSortOrdervalidators, so invalid values return 400. Default isupdatedAt desc(newest first).ElasticSearchClient/OpenSearchClient— a sharedbuildPageHierarchySortOptionsapplies the requested primary sort, then always appendsfullyQualifiedName(keyword, unique per page) as a stable tiebreaker sofrom/sizepagination cannot miss or duplicate hits when the primary sort field is non-unique. UsesEntity.FIELD_FULLY_QUALIFIED_NAME+ aSORT_ORDER_DESCconstant rather than raw literals.SearchClient/KnowledgePageRepository— signature threading only.The Collate
ElasticSearchClientExt/OpenSearchClientExtoverride these same methods; the matching Collate change is in openmetadata-collate (linked below).Tests
KnowledgePageHierarchyITgains three cases: invalidsortBy→ 400, invalidsortOrder→ 400, and a name asc/desc ordering assertion (Awaitility-gated on the search index).Verified end-to-end on a real Collate stack against both Elasticsearch 9.3.0 and OpenSearch 3.4.0:
sortBy=nameasc/desc and theupdatedAt descdefault all order correctly.Greptile Summary
The PR adds configurable, deterministic sorting to Context Center page-hierarchy searches and refreshes the article tree after successful edits.
sortByandsortOrderparameters through the resource, repository, and search-client layers.Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
updatedAt descdefault.Sequence Diagram
Reviews (5): Last reviewed commit: "chore(contextCenter): extract duplicated..." | Re-trigger Greptile
Context used (3)