mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-24 04:10:15 +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,24 +1,25 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { Message } = require('../../models/Message');
|
||||
const reduceHits = require('../../lib/utils/reduceHits');
|
||||
const { Conversation } = require('../../models/Conversation');
|
||||
const {reduceMessages, reduceHits} = require('../../lib/utils/reduceHits');
|
||||
// const { MeiliSearch } = require('meilisearch');
|
||||
|
||||
router.get('/sync', async function (req, res) {
|
||||
// await Message.setMeiliIndexSettings({ primaryKey: 'messageId' });
|
||||
// res.send('updated settings');
|
||||
// await Message.clearMeiliIndex();
|
||||
// res.send('deleted index');
|
||||
await Message.syncWithMeili();
|
||||
await Conversation.syncWithMeili();
|
||||
res.send('synced');
|
||||
});
|
||||
|
||||
router.get('/', async function (req, res) {
|
||||
const { q } = req.query;
|
||||
const result = await Message.meiliSearch({ query: q });
|
||||
const sortedHits = reduceHits(result.hits);
|
||||
console.log(sortedHits);
|
||||
res.send(sortedHits);
|
||||
const message = await Message.meiliSearch(q, { attributesToHighlight: ['text', 'sender'] });
|
||||
const title = await Conversation.meiliSearch(q, { attributesToHighlight: ['title'] });
|
||||
// console.log('titles', title);
|
||||
// console.log(sortedHits);
|
||||
const sortedHits = reduceHits(message.hits, title.hits);
|
||||
// const sortedHits = reduceMessages(message.hits);
|
||||
res.status(200).send({sortedHits});
|
||||
});
|
||||
|
||||
router.get('/clear', async function (req, res) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue