@@ -711,23 +711,33 @@ export function getRecorderSelectionClockRange(
711711 }
712712}
713713
714- export function searchSessions ( sessions : t . SessionUIListing [ ] , searchQuery : string ) : t . SessionUIListing [ ] {
714+ export function searchSessions (
715+ sessions : t . SessionUIListing [ ] ,
716+ searchQuery : string ,
717+ recentLimit : number ,
718+ ) : t . SessionUIListing [ ] {
715719 const searchQueryNorm = _ . toLower ( _ . trim ( searchQuery || '' ) ) ;
716- if ( ! searchQueryNorm ) return sessions ;
717-
718720 const tokens = searchQueryNorm . split ( / \s + / ) ;
719721
720- let pairs = sessions . map ( listing => ( {
721- listing,
722- score :
723- ( ( getTokensMatchScore ( getFields ( listing . head ) ) *
724- ( listing . publication ? listing . publication . likes * 20 + listing . publication . views : 1 ) ) /
725- 10 ) *
726- ( listing . head . isClip ? 1 : 2 ) ,
727- } ) ) ;
728- pairs = _ . filter ( pairs , 'score' ) ;
729- pairs = _ . orderBy ( pairs , 'score' , 'desc' ) ;
730- return _ . map ( pairs , 'listing' ) ;
722+ let pairs = sessions . map ( listing => {
723+ const matchScore = searchQueryNorm ? getTokensMatchScore ( getFields ( listing . head ) ) : 1 ;
724+ const statsScore = ( listing . publication ? listing . publication . likes * 20 + listing . publication . views : 1 ) / 10 ;
725+ const clipScore = listing . head . isClip ? 1 : 2 ;
726+ const score = matchScore * statsScore * clipScore ;
727+ return { listing, score } ;
728+ } ) ;
729+
730+ let groupedPairs = _ . groupBy ( pairs , p => p . listing . group ) ;
731+ let recentPairs = groupedPairs . recent ?? [ ] ;
732+ let currentPairs = groupedPairs . current ?? [ ] ;
733+ let remotePairs = groupedPairs . remote ?? [ ] ;
734+
735+ remotePairs = _ . filter ( remotePairs , 'score' ) ;
736+ remotePairs = _ . reject ( remotePairs , p => recentPairs . some ( recent => recent . listing . head . id === p . listing . head . id ) ) ;
737+ remotePairs = _ . orderBy ( remotePairs , 'score' , 'desc' ) ;
738+ recentPairs = _ . take ( _ . filter ( recentPairs , 'score' ) , recentLimit ) ;
739+
740+ return _ . map ( [ ...recentPairs , ...currentPairs , ...remotePairs ] , 'listing' ) ;
731741
732742 function getFields ( head : t . SessionHead ) : string [ ] {
733743 return [
@@ -759,15 +769,15 @@ export function searchSessions(sessions: t.SessionUIListing[], searchQuery: stri
759769 }
760770}
761771
762- export function limitRecentSessions ( sessions : t . SessionUIListing [ ] , limit : number ) : t . SessionUIListing [ ] {
763- let res = [ ] ;
764- let count = 0 ;
765- for ( const listing of sessions ) {
766- if ( listing . group === 'recent' ) {
767- if ( count >= limit ) continue ;
768- count ++ ;
769- }
770- res . push ( listing ) ;
771- }
772- return res ;
773- }
772+ // export function limitRecentSessions(sessions: t.SessionUIListing[], limit: number): t.SessionUIListing[] {
773+ // let res = [];
774+ // let count = 0;
775+ // for (const listing of sessions) {
776+ // if (listing.group === 'recent') {
777+ // if (count >= limit) continue;
778+ // count++;
779+ // }
780+ // res.push(listing);
781+ // }
782+ // return res;
783+ // }
0 commit comments