Skip to content

Commit

Permalink
feat: Wrap the searched chunk with a Popover infiniflow#2247
Browse files Browse the repository at this point in the history
  • Loading branch information
cike8899 committed Sep 12, 2024
1 parent 4158697 commit 21b3edc
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 8 deletions.
5 changes: 4 additions & 1 deletion web/src/components/highlight-markdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import classNames from 'classnames';
import Markdown from 'react-markdown';
import SyntaxHighlighter from 'react-syntax-highlighter';
import rehypeRaw from 'rehype-raw';
Expand All @@ -7,14 +8,16 @@ import styles from './index.less';

const HightLightMarkdown = ({
children,
className,
}: {
children: string | null | undefined;
className?: string;
}) => {
return (
<Markdown
remarkPlugins={[remarkGfm]}
rehypePlugins={[rehypeRaw]}
className={styles.text}
className={classNames(styles.text, className)}
components={
{
code(props: any) {
Expand Down
7 changes: 6 additions & 1 deletion web/src/components/image/index.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
.primitiveImg {
display: inline-block;
max-height: 100px;
}

.image {
width: 100px;
max-width: 100px;
object-fit: contain;
}

Expand Down
3 changes: 2 additions & 1 deletion web/src/components/image/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { api_host } from '@/utils/api';
import { Popover } from 'antd';
import classNames from 'classnames';

import styles from './index.less';

Expand All @@ -14,7 +15,7 @@ const Image = ({ id, className, ...props }: IImage) => {
{...props}
src={`${api_host}/document/image/${id}`}
alt=""
className={className}
className={classNames(styles.primitiveImg, className)}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions web/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ The above is the content you need to summarize.`,
tts: 'Text to speech',
ttsTip:
'To play the voice using voice conversion, please select TTS (speech conversion model) in the settings first.',
relatedQuestion: 'Related question',
},
setting: {
profile: 'Profile',
Expand Down
3 changes: 2 additions & 1 deletion web/src/locales/zh-traditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ export default {
read: '朗讀內容',
tts: '文字轉語音',
ttsTip: '是否用語音轉換播放語音,請先在設定裡面選擇TTS(語音轉換模型)。',
relatedQuestion: '相關問題',
},
setting: {
profile: '概述',
Expand Down Expand Up @@ -832,7 +833,7 @@ export default {
wenCai: '問財',
queryType: '查詢類型',
wenCaiDescription:
'該組件可用於獲取廣泛的金融領域的信息,包括但不限於股票、基金等...',
'該組件可用於獲取廣泛的金融領域的o息,包括但不限於股票、基金等...',
wenCaiQueryTypeOptions: {
stock: '股票',
zhishu: '指數',
Expand Down
1 change: 1 addition & 0 deletions web/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ export default {
read: '朗读内容',
tts: '文本转语音',
ttsTip: '是否用语音转换播放语音,请先在设置里面选择TTS(语音转换模型)。',
relatedQuestion: '相关问题',
},
setting: {
profile: '概要',
Expand Down
6 changes: 6 additions & 0 deletions web/src/pages/search/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,9 @@
background-position: 200% center;
}
}

.popupMarkdown {
width: 60vw;
max-height: 40vh;
overflow: auto;
}
21 changes: 17 additions & 4 deletions web/src/pages/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
List,
Pagination,
PaginationProps,
Popover,
Skeleton,
Space,
Tag,
Expand Down Expand Up @@ -150,17 +151,29 @@ const SearchPage = () => {
<ImageWithPopover
id={item.img_id}
></ImageWithPopover>
<HightLightMarkdown>
{item.highlight}
</HightLightMarkdown>
<Popover
content={
<div className={styles.popupMarkdown}>
<HightLightMarkdown>
{item.content_with_weight}
</HightLightMarkdown>
</div>
}
>
<div>
<HightLightMarkdown>
{item.highlight}
</HightLightMarkdown>
</div>
</Popover>
</Space>
</Card>
</List.Item>
)}
/>
)}
{relatedQuestions?.length > 0 && (
<Card>
<Card title={t('chat.relatedQuestion')}>
<Flex wrap="wrap" gap={'10px 0'}>
{relatedQuestions?.map((x, idx) => (
<Tag
Expand Down

0 comments on commit 21b3edc

Please sign in to comment.