Implementation:Infiniflow Ragflow NextSearchHooks
| Knowledge Sources | |
|---|---|
| Domains | Frontend, Search |
| Last Updated | 2026-02-12 06:00 GMT |
Overview
Concrete core search hooks with SSE streaming and state management provided by the RAGFlow frontend.
Description
The next-search/hooks module exports hooks that power the search page: `useGetSharedSearchParams` (extracts shared search URL params), `useSearchFetchMindMap` / `useShowMindMapDrawer` (fetches and controls mind map visualization), `useTestChunkRetrieval` / `useTestChunkAllRetrieval` (chunk retrieval testing with pagination), `useTestRetrieval` (combines retrieval with document filtering), `useFetchRelatedQuestions` (fetches related question suggestions), `useSendQuestion` (orchestrates SSE-based AI answer streaming, chunk retrieval, and related questions in parallel), `useSearching` (top-level composition hook that wires everything together including mind map, pagination, and document preview drawer), `useCheckSettings` (validates search app configuration), and `usePendingMindMap` (loading progress timer).
Usage
Import `useSearching` as the primary hook in the search page component. Import individual hooks when building custom search UI compositions or testing utilities.
Code Reference
Source Location
- Repository: Infiniflow_Ragflow
- File: web/src/pages/next-search/hooks.ts
- Lines: 1-604
Signature
export interface ISearchingProps {
searchText?: string;
data: ISearchAppDetailProps;
setIsSearching?: Dispatch<SetStateAction<boolean>>;
setSearchText?: Dispatch<SetStateAction<string>>;
}
export type ISearchReturnProps = ReturnType<typeof useSearching>;
export const useGetSharedSearchParams = () => { from; sharedId; locale; tenantId; data; visibleAvatar };
export const useSearchFetchMindMap = () => { data; loading; fetchMindMap };
export const useShowMindMapDrawer = (kbIds: string[], question: string, searchId?: string) => { ... };
export const useTestChunkRetrieval = (tenantId?: string) => { data; loading; testChunk };
export const useTestChunkAllRetrieval = (tenantId?: string) => { data; loading; testChunkAll };
export const useTestRetrieval = (kbIds: string[], searchStr: string, sendingLoading: boolean) => { ... };
export const useFetchRelatedQuestions = (tenantId?: string, searchId?: string) => { data; loading; fetchRelatedQuestions };
export const useSendQuestion = (kbIds: string[], tenantId?: string, searchId?: string, related_search?: boolean) => { ... };
export const useSearching = (props: ISearchingProps) => ISearchReturnProps;
export const useCheckSettings = (data: ISearchAppDetailProps) => { openSetting: boolean };
export const usePendingMindMap = () => number;
Import
import { useSearching, useCheckSettings, ISearchReturnProps } from '@/pages/next-search/hooks';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| searchText | string | No | Initial search text to trigger on mount |
| data | ISearchAppDetailProps | Yes | Search application configuration including kb_ids, summary, related_search settings |
| setIsSearching | Dispatch<SetStateAction<boolean>> | No | Callback to toggle search state in parent |
| setSearchText | Dispatch<SetStateAction<string>> | No | Callback to clear search text in parent after consumption |
Outputs
| Name | Type | Description |
|---|---|---|
| answer | IAnswer | Current AI-generated answer from SSE stream |
| sendingLoading | boolean | Whether the AI answer is still being streamed |
| chunks | IChunk[] | Retrieved document chunks matching the query |
| total | number | Total number of matching chunks |
| relatedQuestions | string[] | Suggested related questions (up to 5) |
| searchStr | string | Current search input value |
| handleSearch | (value: string) => void | Triggers search with given query text |
| pagination | object | Current pagination state |
| onChange | (page: number, pageSize: number) => void | Pagination change handler |
Usage Examples
import { useSearching } from '@/pages/next-search/hooks';
const searchProps = useSearching({
searchText: initialQuery,
data: searchAppDetail,
setIsSearching,
});
return <SearchingView {...searchProps} searchData={searchAppDetail} />;