mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-10 19:44:23 +01:00
backend logic drafted, moving to frontend
This commit is contained in:
parent
4f5ee8b198
commit
610cba4a60
8 changed files with 237 additions and 72 deletions
|
|
@ -1,8 +1,8 @@
|
|||
const mergeSort = require('./mergeSort');
|
||||
|
||||
function reduceHits(hits) {
|
||||
function reduceMessages(hits) {
|
||||
const counts = {};
|
||||
|
||||
|
||||
for (const hit of hits) {
|
||||
if (!counts[hit.conversationId]) {
|
||||
counts[hit.conversationId] = 1;
|
||||
|
|
@ -10,17 +10,47 @@ function reduceHits(hits) {
|
|||
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;
|
||||
function reduceHits(hits, titles = []) {
|
||||
const counts = {};
|
||||
const titleMap = {};
|
||||
const convos = [...hits, ...titles];
|
||||
|
||||
for (const convo of convos) {
|
||||
if (!counts[convo.conversationId]) {
|
||||
counts[convo.conversationId] = 1;
|
||||
} else {
|
||||
counts[convo.conversationId]++;
|
||||
}
|
||||
|
||||
if (convo.title) {
|
||||
titleMap[convo.conversationId] = convo._formatted.title;
|
||||
}
|
||||
}
|
||||
|
||||
const result = [];
|
||||
|
||||
for (const [conversationId, count] of Object.entries(counts)) {
|
||||
result.push({
|
||||
conversationId,
|
||||
count,
|
||||
title: titleMap[conversationId] ? titleMap[conversationId] : null
|
||||
});
|
||||
}
|
||||
|
||||
return mergeSort(result, (a, b) => b.count - a.count);
|
||||
}
|
||||
|
||||
module.exports = { reduceMessages, reduceHits };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue