search-view.tsx
Overview
search-view.tsx defines the SearchingView React functional component, which serves as the main interactive search interface in the application. This component provides a rich user experience for querying a knowledge base or document repository with features such as:
Search input with live update and "Enter" key submission.
Display of AI-generated answer summaries in Markdown format.
Retrieval and display of relevant document chunks with highlights and popovers.
Pagination controls for navigating search results.
Related questions suggestions for exploration.
Integration with visual tools like a Mind Map drawer.
PDF document preview in a modal drawer.
Loading skeletons and state handling during asynchronous operations.
The component is highly configurable and interacts with several UI sub-components and utilities to deliver a comprehensive search and retrieval experience.
Component: SearchingView
Props
The component receives a large set of props, mainly typed by ISearchReturnProps augmented by some additional props:
Prop Name | Type | Description |
|---|---|---|
|
| Setter to toggle the searching state in the parent component. |
|
| Contains configuration and metadata for the search application, including summary and kb_ids. |
| Callback to handle clicks on related questions. | |
| Callback for testing a specific chunk of retrieved data. | |
|
| Setter for managing selected document IDs. |
| AI-generated answer summary and optional reference data. | |
|
| Indicates if a search request/response is in progress. |
|
| List of related questions to display as suggestions. |
|
| Flag indicating whether this is the first render of the component. |
|
| Currently selected document IDs. |
|
| Indicates if the current search string is empty. |
|
| The current search string. |
| Function to stop ongoing message output (e.g., cancel an in-progress search). | |
|
| Visibility flag for the PDF preview drawer. |
| Function to close/hide the PDF preview drawer. | |
|
| Currently selected document ID for preview. |
|
| Currently selected chunk of document data. |
| Handler when a document button is clicked. | |
|
| Visibility of the Mind Map drawer. |
| Function to hide the Mind Map drawer modal. | |
| Function to show the Mind Map drawer modal. | |
|
| Loading state of the Mind Map data. |
|
| Mind Map data structure passed to the Mind Map drawer. |
|
| Array of retrieved document chunks from the search. |
| Total number of search results. | |
| Callback to execute a search query. | |
| Pagination state object. | |
| Pagination page change handler. |
Internal State
searchtext(string): Local state that reflects the current search input value. It is synchronized with thesearchStrprop via auseEffect.
Component Structure and Behavior
The component renders a search interface divided primarily into:
Header Section:
Displays the "RAGFlow" title, which when clicked, resets the searching state.
Contains the search input box with:
Placeholder text (localized).
Clear (X) button to reset the input and related questions.
Search/stop button that toggles between a loading indicator and a search icon.
Pressing Enter triggers
handleSearch.
The input is disabled while a search request is loading.
Search Body:
If enabled (
searchData.search_config.summary) and the search string is non-empty:Displays an AI Summary heading.
Shows a skeleton loader if the answer is loading.
Otherwise, renders the answer content using
MarkdownContentwith references and clickable document buttons.
Displays retrieval documents via the
RetrievalDocumentscomponent with selection handlers.Lists
chunksof retrieved document content:Each chunk displays an image preview (
ImageWithPopover), sanitized highlighted text with a popover showing weighted content in Markdown (HightLightMarkdown).Document buttons with icons (
FileIcon) allow interaction per chunk.
Displays related questions as clickable buttons if enabled.
Pagination controls (
RAGFlowPagination) appear if there are multiple pages of results.
Mind Map Drawer:
Conditionally rendered when
mindMapVisibleis true.Displays a
MindMapDrawercomponent with loading and data state.When hidden, if applicable, a floating button with an icon allows the user to open the Mind Map drawer.
PDF Preview Drawer:
Controlled by the
visibleprop.Renders a
PdfDrawercomponent for viewing document chunks in detail.
Usage Example
<SearchingView
setIsSearching={setIsSearching}
searchData={searchData}
handleClickRelatedQuestion={(question) => console.log('Related question:', question)}
handleTestChunk={(chunk) => console.log('Test chunk:', chunk)}
setSelectedDocumentIds={setSelectedIds}
answer={{ answer: "AI generated summary", reference: someReference }}
sendingLoading={false}
relatedQuestions={["What is RAGFlow?", "How to use search?"]}
isFirstRender={false}
selectedDocumentIds={selectedIds}
isSearchStrEmpty={false}
searchStr={"query text"}
stopOutputMessage={() => console.log("Stop message")}
visible={false}
hideModal={() => setVisible(false)}
documentId={"doc123"}
selectedChunk={selectedChunk}
clickDocumentButton={(docId, chunk) => console.log(docId, chunk)}
mindMapVisible={false}
hideMindMapModal={() => {}}
showMindMapModal={() => {}}
mindMapLoading={false}
mindMap={mindMapData}
chunks={retrievedChunks}
total={50}
handleSearch={(text) => search(text)}
pagination={{ current: 1, pageSize: 10 }}
onChange={(page) => changePage(page)}
/>
Important Implementation Details
Sanitization: Highlighted chunk content is sanitized using
DOMPurifybefore being dangerously set as inner HTML to prevent XSS.Markdown Rendering: AI answer summaries and chunk content are rendered with Markdown components (
MarkdownContent,HightLightMarkdown), allowing rich text display.Popover Usage: Popovers provide detailed views of chunk content on demand, improving UX by hiding verbose text until needed.
State Synchronization: The internal
searchtextstate is kept synchronized with the externalsearchStrprop, enabling controlled input behavior.Conditional Rendering: Many UI elements are conditionally rendered based on search config flags, input emptiness, loading states, and visibility toggles.
Accessibility & UX: Input disables during loading, buttons have clear icons, and pagination ensures manageable navigation over large results.
Interaction with Other Parts of the Application
UI Components: Utilizes shared UI components like
Input,SkeletonCard,Button,Popover, and custom components likePdfDrawer,MindMapDrawer, etc.Icons: Uses vector icons from
lucide-reactfor visual cues.Localization: Uses
react-i18nextfor translation/localization of strings.State Management: Receives state setters and handlers from parent components for search control, document selection, pagination, and drawer visibility.
Data Interfaces: Relies on
ISearchAppDetailPropsandISearchReturnPropsinterfaces to tightly couple with the data model of the search backend.Utility Functions: Uses utility helpers like
cnfor conditional classNames andisEmptyfrom lodash.
This file acts as the central search UI, tying together data fetching, user input, document retrieval, and advanced visualization features like mind maps and PDF previews.
Visual Diagram
componentDiagram
component SearchingView {
+searchtext: string (state)
+setSearchtext()
+useEffect()
+render()
}
component Input {
+value
+onChange
+onKeyUp
+disabled
}
component Button {
+onClick
+variant
}
component Popover {
+PopoverTrigger
+PopoverContent
}
component MarkdownContent {
+content
+loading
+reference
}
component HightLightMarkdown {
+children
}
component RetrievalDocuments {
+selectedDocumentIds
+setSelectedDocumentIds
+onTesting
}
component RAGFlowPagination {
+current
+pageSize
+total
+onChange
}
component PdfDrawer {
+visible
+hideModal
+documentId
+chunk
}
component MindMapDrawer {
+visible
+hideModal
+data
+loading
}
SearchingView --> Input : renders
SearchingView --> Button : renders
SearchingView --> Popover : renders
SearchingView --> MarkdownContent : renders AI summary
SearchingView --> HightLightMarkdown : renders chunk content
SearchingView --> RetrievalDocuments : renders doc selector
SearchingView --> RAGFlowPagination : renders pagination
SearchingView --> PdfDrawer : renders PDF preview modal
SearchingView --> MindMapDrawer : renders Mind Map modal
Summary
search-view.tsx is the core React component that implements the search UI for an AI-augmented retrieval application. It integrates numerous UI elements, manages input and asynchronous states, sanitizes and renders rich content, and supports advanced features like mind maps and PDF previews. It is designed to be flexible, user-friendly, and tightly integrated with the application's data and state management layers.