Merge pull request #122 from danny-avila/fix-search

Fix search
This commit is contained in:
Danny Avila 2023-03-24 18:45:03 -04:00 committed by GitHub
commit e2ad9accbe
6 changed files with 23 additions and 14 deletions

View file

@ -1,6 +1,6 @@
const cleanUpPrimaryKeyValue = (value) => {
// For Bing convoId handling
return value.replace(/--/g, '-');
return value.replace(/--/g, '|');
};
function replaceSup(text) {

View file

@ -1,4 +1,5 @@
const mergeSort = require('./mergeSort');
const { cleanUpPrimaryKeyValue } = require('./misc');
function reduceMessages(hits) {
const counts = {};
@ -29,15 +30,16 @@ function reduceHits(hits, titles = []) {
const convos = [...hits, ...titles];
for (const convo of convos) {
if (!counts[convo.conversationId]) {
counts[convo.conversationId] = 1;
const currentId = cleanUpPrimaryKeyValue(convo.conversationId);
if (!counts[currentId]) {
counts[currentId] = 1;
} else {
counts[convo.conversationId]++;
counts[currentId]++;
}
if (convo.title) {
// titleMap[convo.conversationId] = convo._formatted.title;
titleMap[convo.conversationId] = convo.title;
// titleMap[currentId] = convo._formatted.title;
titleMap[currentId] = convo.title;
}
}

View file

@ -1,6 +1,5 @@
// const { Conversation } = require('./plugins');
const Conversation = require('./schema/convoSchema');
const { cleanUpPrimaryKeyValue } = require('../lib/utils/misc');
const { getMessages, deleteMessages } = require('./Message');
const getConvo = async (user, conversationId) => {
@ -90,7 +89,7 @@ module.exports = {
promises.push(
Conversation.findOne({
user,
conversationId: cleanUpPrimaryKeyValue(convo.conversationId)
conversationId: convo.conversationId,
}).exec()
)
);

View file

@ -15,7 +15,8 @@ router.get('/sync', async function (req, res) {
router.get('/', async function (req, res) {
try {
const user = req?.session?.user?.username;
let user = req?.session?.user?.username;
user = user ?? null;
const { q } = req.query;
const pageNumber = req.query.pageNumber || 1;
const key = `${user || ''}${q}`;
@ -50,8 +51,10 @@ router.get('/', async function (req, res) {
};
});
const titles = (await Conversation.meiliSearch(q)).hits;
console.log('message hits:', messages.length, 'convo hits:', titles.length);
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 activeMessages = [];

View file

@ -8,8 +8,8 @@ import rehypeRaw from 'rehype-raw'
import CodeBlock from './CodeBlock';
import { langSubset } from '~/utils/languages';
const Content = React.memo(({ content, isCreatedByUser = false }) => {
const rehypePlugins = [
const Content = React.memo(({ content, isCreatedByUser = true }) => {
let rehypePlugins = [
[rehypeKatex, { output: 'mathml' }],
[
rehypeHighlight,
@ -20,12 +20,15 @@ const Content = React.memo(({ content, isCreatedByUser = false }) => {
}
],
[rehypeRaw],
]
];
rehypePlugins = isCreatedByUser ? rehypePlugins.slice(0, -1) : rehypePlugins;
return (
<>
<ReactMarkdown
remarkPlugins={[remarkGfm, [remarkMath, { singleDollarTextMath: false }]]}
rehypePlugins={isCreatedByUser ? rehypePlugins.slice(-1) : rehypePlugins}
rehypePlugins={rehypePlugins}
linkTarget="_new"
components={{
code,

View file

@ -34,6 +34,8 @@ services:
- ./api:/api
- /api/node_modules
mongodb:
ports:
- 27018:27017
image: mongo
restart: always
container_name: mongodb