mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00
fix: correctly searches bing messages
This commit is contained in:
parent
a46ec62532
commit
34bef48e84
4 changed files with 14 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
||||||
const cleanUpPrimaryKeyValue = (value) => {
|
const cleanUpPrimaryKeyValue = (value) => {
|
||||||
// For Bing convoId handling
|
// For Bing convoId handling
|
||||||
return value.replace(/--/g, '-');
|
return value.replace(/--/g, '|');
|
||||||
};
|
};
|
||||||
|
|
||||||
function replaceSup(text) {
|
function replaceSup(text) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const mergeSort = require('./mergeSort');
|
const mergeSort = require('./mergeSort');
|
||||||
|
const { cleanUpPrimaryKeyValue } = require('./misc');
|
||||||
|
|
||||||
function reduceMessages(hits) {
|
function reduceMessages(hits) {
|
||||||
const counts = {};
|
const counts = {};
|
||||||
|
@ -29,15 +30,16 @@ function reduceHits(hits, titles = []) {
|
||||||
const convos = [...hits, ...titles];
|
const convos = [...hits, ...titles];
|
||||||
|
|
||||||
for (const convo of convos) {
|
for (const convo of convos) {
|
||||||
if (!counts[convo.conversationId]) {
|
const currentId = cleanUpPrimaryKeyValue(convo.conversationId);
|
||||||
counts[convo.conversationId] = 1;
|
if (!counts[currentId]) {
|
||||||
|
counts[currentId] = 1;
|
||||||
} else {
|
} else {
|
||||||
counts[convo.conversationId]++;
|
counts[currentId]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (convo.title) {
|
if (convo.title) {
|
||||||
// titleMap[convo.conversationId] = convo._formatted.title;
|
// titleMap[currentId] = convo._formatted.title;
|
||||||
titleMap[convo.conversationId] = convo.title;
|
titleMap[currentId] = convo.title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// const { Conversation } = require('./plugins');
|
// const { Conversation } = require('./plugins');
|
||||||
const Conversation = require('./schema/convoSchema');
|
const Conversation = require('./schema/convoSchema');
|
||||||
const { cleanUpPrimaryKeyValue } = require('../lib/utils/misc');
|
|
||||||
const { getMessages, deleteMessages } = require('./Message');
|
const { getMessages, deleteMessages } = require('./Message');
|
||||||
|
|
||||||
const getConvo = async (user, conversationId) => {
|
const getConvo = async (user, conversationId) => {
|
||||||
|
@ -90,7 +89,7 @@ module.exports = {
|
||||||
promises.push(
|
promises.push(
|
||||||
Conversation.findOne({
|
Conversation.findOne({
|
||||||
user,
|
user,
|
||||||
conversationId: cleanUpPrimaryKeyValue(convo.conversationId)
|
conversationId: convo.conversationId,
|
||||||
}).exec()
|
}).exec()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,7 +15,8 @@ router.get('/sync', async function (req, res) {
|
||||||
|
|
||||||
router.get('/', async function (req, res) {
|
router.get('/', async function (req, res) {
|
||||||
try {
|
try {
|
||||||
const user = req?.session?.user?.username;
|
let user = req?.session?.user?.username;
|
||||||
|
user = user ?? null;
|
||||||
const { q } = req.query;
|
const { q } = req.query;
|
||||||
const pageNumber = req.query.pageNumber || 1;
|
const pageNumber = req.query.pageNumber || 1;
|
||||||
const key = `${user || ''}${q}`;
|
const key = `${user || ''}${q}`;
|
||||||
|
@ -50,8 +51,10 @@ router.get('/', async function (req, res) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const titles = (await Conversation.meiliSearch(q)).hits;
|
const titles = (await Conversation.meiliSearch(q)).hits;
|
||||||
console.log('message hits:', messages.length, 'convo hits:', titles.length);
|
|
||||||
const sortedHits = reduceHits(messages, titles);
|
const sortedHits = reduceHits(messages, titles);
|
||||||
|
// debugging:
|
||||||
|
// console.log('user:', user, 'message hits:', messages.length, 'convo hits:', titles.length);
|
||||||
|
// console.log('sorted hits:', sortedHits.length);
|
||||||
const result = await getConvosQueried(user, sortedHits, pageNumber);
|
const result = await getConvosQueried(user, sortedHits, pageNumber);
|
||||||
|
|
||||||
const activeMessages = [];
|
const activeMessages = [];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue