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:

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

setIsSearching

Dispatch<SetStateAction<boolean>> (optional)

Setter to toggle the searching state in the parent component.

searchData

ISearchAppDetailProps

Contains configuration and metadata for the search application, including summary and kb_ids.

handleClickRelatedQuestion

(question: string, summary?: boolean) => void

Callback to handle clicks on related questions.

handleTestChunk

(chunk: any) => void

Callback for testing a specific chunk of retrieved data.

setSelectedDocumentIds

Dispatch<SetStateAction<string[]>>

Setter for managing selected document IDs.

answer

{ answer: string; reference?: IReference }

AI-generated answer summary and optional reference data.

sendingLoading

boolean

Indicates if a search request/response is in progress.

relatedQuestions

string[]

List of related questions to display as suggestions.

isFirstRender

boolean

Flag indicating whether this is the first render of the component.

selectedDocumentIds

string[]

Currently selected document IDs.

isSearchStrEmpty

boolean

Indicates if the current search string is empty.

searchStr

string

The current search string.

stopOutputMessage

() => void

Function to stop ongoing message output (e.g., cancel an in-progress search).

visible

boolean

Visibility flag for the PDF preview drawer.

hideModal

() => void

Function to close/hide the PDF preview drawer.

documentId

string

Currently selected document ID for preview.

selectedChunk

any

Currently selected chunk of document data.

clickDocumentButton

(docId: string, chunk: any) => void

Handler when a document button is clicked.

mindMapVisible

boolean

Visibility of the Mind Map drawer.

hideMindMapModal

() => void

Function to hide the Mind Map drawer modal.

showMindMapModal

() => void

Function to show the Mind Map drawer modal.

mindMapLoading

boolean

Loading state of the Mind Map data.

mindMap

any

Mind Map data structure passed to the Mind Map drawer.

chunks

any[]

Array of retrieved document chunks from the search.

total

number

Total number of search results.

handleSearch

(text: string) => void

Callback to execute a search query.

pagination

{ current: number; pageSize: number; }

Pagination state object.

onChange

(page: number) => void

Pagination page change handler.


Internal State


Component Structure and Behavior

The component renders a search interface divided primarily into:

  1. 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.

  2. 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 MarkdownContent with references and clickable document buttons.

    • Displays retrieval documents via the RetrievalDocuments component with selection handlers.

    • Lists chunks of 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.

  3. Mind Map Drawer:

    • Conditionally rendered when mindMapVisible is true.

    • Displays a MindMapDrawer component with loading and data state.

    • When hidden, if applicable, a floating button with an icon allows the user to open the Mind Map drawer.

  4. PDF Preview Drawer:

    • Controlled by the visible prop.

    • Renders a PdfDrawer component 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


Interaction with Other Parts of the Application

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.