mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-02 15:51:49 +01:00
feat: search bar working, still in progress
This commit is contained in:
parent
610cba4a60
commit
0f54ffd8b4
10 changed files with 147 additions and 24 deletions
|
|
@ -85,12 +85,6 @@ const createMeiliMongooseModel = function ({ index, indexName, client, attribute
|
|||
// Push new document to Meili
|
||||
async addObjectToMeili() {
|
||||
const object = _.pick(this.toJSON(), attributesToIndex);
|
||||
// const title = (await this.getTitle()) || 'New Chat'; // Get title value
|
||||
// const objectWithTitle = {
|
||||
// ...this.toJSON(),
|
||||
// title
|
||||
// };
|
||||
// const object = _.pick(objectWithTitle, attributesToIndex); // Pick desired attributes
|
||||
|
||||
try {
|
||||
// console.log('Adding document to Meili', object);
|
||||
|
|
|
|||
|
|
@ -136,6 +136,25 @@ module.exports = {
|
|||
return { message: 'Error getting conversations' };
|
||||
}
|
||||
},
|
||||
getConvosQueried: async (user, convoIds, pageNumber = 1, pageSize = 12) => {
|
||||
try {
|
||||
if (!convoIds || convoIds.length === 0) {
|
||||
return { conversations: [], pages: 1, pageNumber, pageSize };
|
||||
}
|
||||
|
||||
const promises = convoIds.map(convo => {
|
||||
return Conversation.findOne({ user, conversationId: convo.conversationId}).exec();
|
||||
});
|
||||
const results = await Promise.all(promises);
|
||||
const startIndex = (pageNumber - 1) * pageSize;
|
||||
const convos = results.slice(startIndex, startIndex + pageSize);
|
||||
const totalPages = Math.ceil(results.length / pageSize);
|
||||
return { conversations: convos, pages: totalPages, pageNumber, pageSize };
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return { message: 'Error fetching conversations' };
|
||||
}
|
||||
},
|
||||
getConvo,
|
||||
getConvoTitle: async (user, conversationId) => {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { Message } = require('../../models/Message');
|
||||
const { Conversation } = require('../../models/Conversation');
|
||||
const { Conversation, getConvosQueried } = require('../../models/Conversation');
|
||||
const {reduceMessages, reduceHits} = require('../../lib/utils/reduceHits');
|
||||
// const { MeiliSearch } = require('meilisearch');
|
||||
|
||||
|
|
@ -13,13 +13,18 @@ router.get('/sync', async function (req, res) {
|
|||
|
||||
router.get('/', async function (req, res) {
|
||||
const { q } = req.query;
|
||||
const message = await Message.meiliSearch(q, { attributesToHighlight: ['text', 'sender'] });
|
||||
console.log(req.query);
|
||||
const pageNumber = req.query.pageNumber || 1;
|
||||
// const message = await Message.meiliSearch(q, { attributesToHighlight: ['text', 'sender'] });
|
||||
const message = await Message.meiliSearch(q);
|
||||
const title = await Conversation.meiliSearch(q, { attributesToHighlight: ['title'] });
|
||||
// console.log('titles', title);
|
||||
// console.log(sortedHits);
|
||||
const sortedHits = reduceHits(message.hits, title.hits);
|
||||
const result = await getConvosQueried(req?.session?.user?.username, sortedHits, pageNumber);
|
||||
// const sortedHits = reduceMessages(message.hits);
|
||||
res.status(200).send({sortedHits});
|
||||
// res.status(200).send(sortedHits || result);
|
||||
res.status(200).send(result);
|
||||
});
|
||||
|
||||
router.get('/clear', async function (req, res) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue