From 52c201bae3487b84217931292736aeec6544f0ea Mon Sep 17 00:00:00 2001 From: Nick Savage Date: Fri, 3 Jan 2025 15:25:26 -0500 Subject: [PATCH] frontend: fix sorting of search results --- zettelkasten-front/src/pages/cards/SearchPage.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/zettelkasten-front/src/pages/cards/SearchPage.tsx b/zettelkasten-front/src/pages/cards/SearchPage.tsx index aaab08c..0ca1038 100644 --- a/zettelkasten-front/src/pages/cards/SearchPage.tsx +++ b/zettelkasten-front/src/pages/cards/SearchPage.tsx @@ -166,16 +166,15 @@ export function SearchPage({ const filteredCards = onlyParentCards ? cards.filter(card => !card.card_id.includes("/")) : cards; + const sortedCards = sortCards(filteredCards, sortBy); const indexOfLastItem = currentPage * itemsPerPage; const indexOfFirstItem = indexOfLastItem - itemsPerPage; - return filteredCards.slice(indexOfFirstItem, indexOfLastItem); + return sortedCards.slice(indexOfFirstItem, indexOfLastItem); } else { const filteredResults = onlyParentCards ? searchResults.filter(result => !result.id.includes("/")) : searchResults; - const indexOfLastItem = currentPage * itemsPerPage; - const indexOfFirstItem = indexOfLastItem - itemsPerPage; - return filteredResults.slice(indexOfFirstItem, indexOfLastItem).map(result => ({ + const sortedResults = sortCards(filteredResults.map(result => ({ id: Number(result.metadata?.id) || 0, card_id: result.id, title: result.title, @@ -190,7 +189,11 @@ export function SearchPage({ combined_score: result.score, shared_entities: result.metadata?.shared_entities || 0, entity_similarity: result.metadata?.entity_similarity || 0, - } as CardChunk)); + } as CardChunk)), sortBy); + + const indexOfLastItem = currentPage * itemsPerPage; + const indexOfFirstItem = indexOfLastItem - itemsPerPage; + return sortedResults.slice(indexOfFirstItem, indexOfLastItem); } }