mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
26 lines
507 B
JavaScript
26 lines
507 B
JavaScript
|
|
const mergeSort = require('./mergeSort');
|
||
|
|
|
||
|
|
function reduceHits(hits) {
|
||
|
|
const counts = {};
|
||
|
|
|
||
|
|
for (const hit of hits) {
|
||
|
|
if (!counts[hit.conversationId]) {
|
||
|
|
counts[hit.conversationId] = 1;
|
||
|
|
} else {
|
||
|
|
counts[hit.conversationId]++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
const result = [];
|
||
|
|
|
||
|
|
for (const [conversationId, count] of Object.entries(counts)) {
|
||
|
|
result.push({
|
||
|
|
conversationId,
|
||
|
|
count
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
return mergeSort(result, (a, b) => b.count - a.count);
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = reduceHits;
|