Skip to content

Commit

Permalink
Implement sorting logic for llm tags display
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanFengYeh committed Dec 28, 2024
1 parent 3491c7a commit 3fd6bdb
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions components/search/HierarchicalMenuWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ export const connectMultiselectHierarchicalMenu: MultiselectHierarchicalMenuConn
attribute: string,
isParent: boolean
): MultiselectHierarchicalMenuItem[] => {
// Safely attempt to retrieve facet values, default to an empty array if unavailable
const sortByParameter = isParent ? ["name:asc"] : ["count:desc"]

const facetValues =
(results?.getFacetValues(attribute, {
sortBy: ["name:asc"]
sortBy: sortByParameter
}) as SearchResults.FacetValue[]) || []

// Mapping over facetValues with an additional safety check
Expand Down Expand Up @@ -113,13 +114,7 @@ export const connectMultiselectHierarchicalMenu: MultiselectHierarchicalMenuConn
return resultsItem ? { ...levelItem, ...resultsItem } : levelItem
})

return mergedItems.sort((a, b) => {
// if (isParent) {
// return a.label.localeCompare(b.label) // Alphabetical sort for parent
// } else {
return b.count - a.count // Sort by count descending for child
// }
})
return mergedItems
}

// Register refinements and items for each attribute.
Expand Down

0 comments on commit 3fd6bdb

Please sign in to comment.