Skip to content

Commit e6cb74b

Browse files
authored
Fix (next search): Optimize the search problem interface and related functions #3221 (#9569)
### What problem does this PR solve? Fix (next search): Optimize the search problem interface and related functions #3221 -Add search_id to the retrievval_test interface -Optimize handleSearchStrChange and handleSearch callbacks to determine whether to enable AI search based on search configuration ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
1 parent 00f54c2 commit e6cb74b

File tree

10 files changed

+147
-164
lines changed

10 files changed

+147
-164
lines changed

web/src/components/home-card.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { RAGFlowAvatar } from '@/components/ragflow-avatar';
2+
import { Card, CardContent } from '@/components/ui/card';
3+
import { formatDate } from '@/utils/date';
4+
5+
interface IProps {
6+
data: {
7+
name: string;
8+
description?: string;
9+
avatar?: string;
10+
update_time?: string | number;
11+
};
12+
onClick?: () => void;
13+
moreDropdown: React.ReactNode;
14+
}
15+
export function HomeCard({ data, onClick, moreDropdown }: IProps) {
16+
return (
17+
<Card
18+
className="bg-bg-card border-colors-outline-neutral-standard"
19+
onClick={() => {
20+
// navigateToSearch(data?.id);
21+
onClick?.();
22+
}}
23+
>
24+
<CardContent className="p-4 flex gap-2 items-start group h-full">
25+
<div className="flex justify-between mb-4">
26+
<RAGFlowAvatar
27+
className="w-[32px] h-[32px]"
28+
avatar={data.avatar}
29+
name={data.name}
30+
/>
31+
</div>
32+
<div className="flex flex-col justify-between gap-1 flex-1 h-full w-[calc(100%-50px)]">
33+
<section className="flex justify-between">
34+
<div className="text-[20px] font-bold w-80% leading-5">
35+
{data.name}
36+
</div>
37+
{moreDropdown}
38+
</section>
39+
40+
<section className="flex flex-col gap-1 mt-1">
41+
<div className="whitespace-nowrap overflow-hidden text-ellipsis">
42+
{data.description}
43+
</div>
44+
<div>
45+
<p className="text-sm opacity-80">
46+
{formatDate(data.update_time)}
47+
</p>
48+
</div>
49+
</section>
50+
</div>
51+
</CardContent>
52+
</Card>
53+
);
54+
}
Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
import { HomeCard } from '@/components/home-card';
12
import { MoreButton } from '@/components/more-button';
2-
import { RAGFlowAvatar } from '@/components/ragflow-avatar';
3-
import { SharedBadge } from '@/components/shared-badge';
4-
import { Card, CardContent } from '@/components/ui/card';
53
import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
64
import { IFlow } from '@/interfaces/database/agent';
7-
import { formatDate } from '@/utils/date';
85
import { AgentDropdown } from './agent-dropdown';
96
import { useRenameAgent } from './use-rename-agent';
107

@@ -16,36 +13,16 @@ export function AgentCard({ data, showAgentRenameModal }: DatasetCardProps) {
1613
const { navigateToAgent } = useNavigatePage();
1714

1815
return (
19-
<Card key={data.id} className="w-40" onClick={navigateToAgent(data.id)}>
20-
<CardContent className="p-2.5 pt-2 group">
21-
<section className="flex justify-between mb-2">
22-
<div className="flex gap-2 items-center">
23-
<RAGFlowAvatar
24-
className="size-6 rounded-lg"
25-
avatar={data.avatar}
26-
name={data.title || 'CN'}
27-
></RAGFlowAvatar>
28-
<SharedBadge>{data.nickname}</SharedBadge>
29-
</div>
30-
<AgentDropdown
31-
showAgentRenameModal={showAgentRenameModal}
32-
agent={data}
33-
>
34-
<MoreButton></MoreButton>
35-
</AgentDropdown>
36-
</section>
37-
<div className="flex justify-between items-end">
38-
<div className="w-full">
39-
<h3 className="text-lg font-semibold mb-2 line-clamp-1">
40-
{data.title}
41-
</h3>
42-
<p className="text-xs text-text-secondary">{data.description}</p>
43-
<p className="text-xs text-text-secondary">
44-
{formatDate(data.update_time)}
45-
</p>
46-
</div>
47-
</div>
48-
</CardContent>
49-
</Card>
16+
<HomeCard
17+
data={{ ...data, name: data.title, description: data.description || '' }}
18+
moreDropdown={
19+
<AgentDropdown showAgentRenameModal={showAgentRenameModal} agent={data}>
20+
<MoreButton></MoreButton>
21+
</AgentDropdown>
22+
}
23+
onClick={() => {
24+
navigateToAgent(data?.id);
25+
}}
26+
/>
5027
);
5128
}

web/src/pages/agents/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function Agents() {
4646
</ListFilterBar>
4747
</div>
4848
<div className="flex-1 overflow-auto">
49-
<div className="flex flex-wrap gap-4 px-8">
49+
<div className="grid gap-6 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 max-h-[78vh] overflow-auto px-8">
5050
{data.map((x) => {
5151
return (
5252
<AgentCard

web/src/pages/datasets/dataset-card.tsx

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
import { HomeCard } from '@/components/home-card';
12
import { MoreButton } from '@/components/more-button';
2-
import { RAGFlowAvatar } from '@/components/ragflow-avatar';
3-
import { Badge } from '@/components/ui/badge';
43
import { Card, CardContent } from '@/components/ui/card';
54
import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
65
import { IKnowledge } from '@/interfaces/database/knowledge';
7-
import { formatDate } from '@/utils/date';
86
import { ChevronRight } from 'lucide-react';
97
import { DatasetDropdown } from './dataset-dropdown';
108
import { useDisplayOwnerName } from './use-display-owner';
@@ -24,47 +22,20 @@ export function DatasetCard({
2422
const owner = displayOwnerName(dataset.tenant_id, dataset.nickname);
2523

2624
return (
27-
<Card
28-
key={dataset.id}
29-
className="w-40"
30-
onClick={navigateToDataset(dataset.id)}
31-
>
32-
<CardContent className="p-2.5 pt-2 group">
33-
<section className="flex justify-between mb-2">
34-
<div className="flex gap-2 items-center">
35-
<RAGFlowAvatar
36-
className="size-6 rounded-lg"
37-
avatar={dataset.avatar}
38-
name={dataset.name || 'CN'}
39-
></RAGFlowAvatar>
40-
{owner && (
41-
<Badge className="h-5 rounded-sm px-1 bg-background-badge text-text-badge">
42-
{owner}
43-
</Badge>
44-
)}
45-
</div>
46-
<DatasetDropdown
47-
showDatasetRenameModal={showDatasetRenameModal}
48-
dataset={dataset}
49-
>
50-
<MoreButton></MoreButton>
51-
</DatasetDropdown>
52-
</section>
53-
<div className="flex justify-between items-end">
54-
<div className="w-full">
55-
<h3 className="text-lg font-semibold mb-2 line-clamp-1">
56-
{dataset.name}
57-
</h3>
58-
<p className="text-xs text-text-secondary">
59-
{dataset.doc_num} files
60-
</p>
61-
<p className="text-xs text-text-secondary">
62-
{formatDate(dataset.update_time)}
63-
</p>
64-
</div>
65-
</div>
66-
</CardContent>
67-
</Card>
25+
<HomeCard
26+
data={{ ...dataset, description: `${dataset.doc_num} files` }}
27+
moreDropdown={
28+
<DatasetDropdown
29+
showDatasetRenameModal={showDatasetRenameModal}
30+
dataset={dataset}
31+
>
32+
<MoreButton></MoreButton>
33+
</DatasetDropdown>
34+
}
35+
onClick={() => {
36+
navigateToDataset(dataset.id);
37+
}}
38+
/>
6839
);
6940
}
7041

web/src/pages/datasets/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default function Datasets() {
7070
</Button>
7171
</ListFilterBar>
7272
<div className="flex-1">
73-
<div className="flex flex-wrap gap-4 max-h-[78vh] overflow-auto px-8">
73+
<div className="grid gap-6 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 max-h-[78vh] overflow-auto px-8">
7474
{kbs.map((dataset) => {
7575
return (
7676
<DatasetCard
Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1+
import { HomeCard } from '@/components/home-card';
12
import { MoreButton } from '@/components/more-button';
2-
import { RAGFlowAvatar } from '@/components/ragflow-avatar';
3-
import { Card, CardContent } from '@/components/ui/card';
43
import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
54
import { IDialog } from '@/interfaces/database/chat';
6-
import { formatDate } from '@/utils/date';
75
import { ChatDropdown } from './chat-dropdown';
86
import { useRenameChat } from './hooks/use-rename-chat';
97

@@ -15,32 +13,21 @@ export function ChatCard({ data, showChatRenameModal }: IProps) {
1513
const { navigateToChat } = useNavigatePage();
1614

1715
return (
18-
<Card key={data.id} className="w-40" onClick={navigateToChat(data.id)}>
19-
<CardContent className="p-2.5 pt-2 group">
20-
<section className="flex justify-between mb-2">
21-
<div className="flex gap-2 items-center">
22-
<RAGFlowAvatar
23-
className="size-6 rounded-lg"
24-
avatar={data.icon}
25-
name={data.name || 'CN'}
26-
></RAGFlowAvatar>
27-
</div>
28-
<ChatDropdown chat={data} showChatRenameModal={showChatRenameModal}>
29-
<MoreButton></MoreButton>
30-
</ChatDropdown>
31-
</section>
32-
<div className="flex justify-between items-end">
33-
<div className="w-full">
34-
<h3 className="text-lg font-semibold mb-2 line-clamp-1 truncate">
35-
{data.name}
36-
</h3>
37-
<p className="text-xs text-text-secondary">{data.description}</p>
38-
<p className="text-xs text-text-secondary">
39-
{formatDate(data.update_time)}
40-
</p>
41-
</div>
42-
</div>
43-
</CardContent>
44-
</Card>
16+
<HomeCard
17+
data={{
18+
name: data.name,
19+
description: data.description,
20+
avatar: data.icon,
21+
update_time: data.update_time,
22+
}}
23+
moreDropdown={
24+
<ChatDropdown chat={data} showChatRenameModal={showChatRenameModal}>
25+
<MoreButton></MoreButton>
26+
</ChatDropdown>
27+
}
28+
onClick={() => {
29+
navigateToChat(data?.id);
30+
}}
31+
/>
4532
);
4633
}

web/src/pages/next-chats/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function ChatList() {
4949
</ListFilterBar>
5050
</div>
5151
<div className="flex-1 overflow-auto">
52-
<div className="flex flex-wrap gap-4 px-8">
52+
<div className="grid gap-6 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 max-h-[84vh] overflow-auto px-8">
5353
{data.dialogs.map((x) => {
5454
return (
5555
<ChatCard

web/src/pages/next-search/hooks.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -288,20 +288,23 @@ export const useSendQuestion = (
288288
const { pagination, setPagination } = useGetPaginationWithRouter();
289289

290290
const sendQuestion = useCallback(
291-
(question: string) => {
291+
(question: string, enableAI: boolean = true) => {
292292
const q = trim(question);
293293
if (isEmpty(q)) return;
294294
setPagination({ page: 1 });
295295
setIsFirstRender(false);
296296
setCurrentAnswer({} as IAnswer);
297-
setSendingLoading(true);
298-
send({ kb_ids: kbIds, question: q, tenantId, search_id: searchId });
297+
if (enableAI) {
298+
setSendingLoading(true);
299+
send({ kb_ids: kbIds, question: q, tenantId, search_id: searchId });
300+
}
299301
testChunk({
300302
kb_id: kbIds,
301303
highlight: true,
302304
question: q,
303305
page: 1,
304306
size: pagination.pageSize,
307+
search_id: searchId,
305308
});
306309

307310
if (related_search) {
@@ -327,12 +330,13 @@ export const useSendQuestion = (
327330
}, []);
328331

329332
const handleClickRelatedQuestion = useCallback(
330-
(question: string) => () => {
331-
if (sendingLoading) return;
333+
(question: string, enableAI: boolean = true) =>
334+
() => {
335+
if (sendingLoading) return;
332336

333-
setSearchStr(question);
334-
sendQuestion(question);
335-
},
337+
setSearchStr(question);
338+
sendQuestion(question, enableAI);
339+
},
336340
[sendQuestion, sendingLoading],
337341
);
338342

@@ -348,6 +352,7 @@ export const useSendQuestion = (
348352
doc_ids: documentIds ?? selectedDocumentIds,
349353
page,
350354
size,
355+
search_id: searchId,
351356
});
352357

353358
testChunkAll({
@@ -357,6 +362,7 @@ export const useSendQuestion = (
357362
doc_ids: [],
358363
page,
359364
size,
365+
search_id: searchId,
360366
});
361367
},
362368
[
@@ -366,6 +372,7 @@ export const useSendQuestion = (
366372
kbIds,
367373
selectedDocumentIds,
368374
testChunkAll,
375+
searchId,
369376
],
370377
);
371378

@@ -430,7 +437,6 @@ export const useSearching = ({
430437

431438
const handleSearchStrChange = useCallback(
432439
(value: string) => {
433-
console.log('handleSearchStrChange', value);
434440
setSearchStr(value);
435441
},
436442
[setSearchStr],
@@ -442,10 +448,16 @@ export const useSearching = ({
442448
useEffect(() => {
443449
if (searchText) {
444450
setSearchStr(searchText);
445-
sendQuestion(searchText);
451+
sendQuestion(searchText, searchData.search_config.summary);
446452
setSearchText?.('');
447453
}
448-
}, [searchText, sendQuestion, setSearchStr, setSearchText]);
454+
}, [
455+
searchText,
456+
sendQuestion,
457+
setSearchStr,
458+
setSearchText,
459+
searchData.search_config.summary,
460+
]);
449461

450462
const {
451463
mindMapVisible,
@@ -462,11 +474,16 @@ export const useSearching = ({
462474

463475
const handleSearch = useCallback(
464476
(value: string) => {
465-
sendQuestion(value);
477+
sendQuestion(value, searchData.search_config.summary);
466478
setSearchStr?.(value);
467479
hideMindMapModal();
468480
},
469-
[setSearchStr, sendQuestion, hideMindMapModal],
481+
[
482+
setSearchStr,
483+
sendQuestion,
484+
hideMindMapModal,
485+
searchData.search_config.summary,
486+
],
470487
);
471488

472489
const { pagination, setPagination } = useGetPaginationWithRouter();

0 commit comments

Comments
 (0)