mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-21 18:55:16 +02:00
feat: add search filtering for SurfSense docs mentions and handle zero-width spaces in citations
This commit is contained in:
parent
982dac47ec
commit
c579d773a9
3 changed files with 12 additions and 6 deletions
|
|
@ -16,8 +16,8 @@ import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button
|
|||
import { cn } from "@/lib/utils";
|
||||
|
||||
// Citation pattern: [citation:CHUNK_ID] or [citation:doc-CHUNK_ID]
|
||||
// Also matches Chinese brackets 【】 as LLM sometimes uses them
|
||||
const CITATION_REGEX = /[\[【]citation:(doc-)?(\d+)[\]】]/g;
|
||||
// Also matches Chinese brackets 【】 and handles zero-width spaces that LLM sometimes inserts
|
||||
const CITATION_REGEX = /[\[【]\u200B?citation:(doc-)?(\d+)\u200B?[\]】]/g;
|
||||
|
||||
// Track chunk IDs to citation numbers mapping for consistent numbering
|
||||
// This map is reset when a new message starts rendering
|
||||
|
|
|
|||
|
|
@ -91,11 +91,15 @@ export const DocumentMentionPicker = forwardRef<
|
|||
}, [debouncedSearch, searchSpaceId]);
|
||||
|
||||
const surfsenseDocsQueryParams = useMemo(() => {
|
||||
return {
|
||||
const params: { page: number; page_size: number; title?: string } = {
|
||||
page: 0,
|
||||
page_size: PAGE_SIZE,
|
||||
};
|
||||
}, []);
|
||||
if (debouncedSearch.trim()) {
|
||||
params.title = debouncedSearch;
|
||||
}
|
||||
return params;
|
||||
}, [debouncedSearch]);
|
||||
|
||||
// Use query for fetching first page of documents
|
||||
const { data: documents, isLoading: isDocumentsLoading } = useQuery({
|
||||
|
|
@ -115,7 +119,7 @@ export const DocumentMentionPicker = forwardRef<
|
|||
|
||||
// Use query for fetching first page of SurfSense docs
|
||||
const { data: surfsenseDocs, isLoading: isSurfsenseDocsLoading } = useQuery({
|
||||
queryKey: ["surfsense-docs-mention", surfsenseDocsQueryParams],
|
||||
queryKey: ["surfsense-docs-mention", debouncedSearch],
|
||||
queryFn: () => documentsApiService.getSurfsenseDocs({ queryParams: surfsenseDocsQueryParams }),
|
||||
staleTime: 3 * 60 * 1000,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -188,7 +188,9 @@ export const getSurfsenseDocsByChunkResponse = surfsenseDocsDocumentWithChunks;
|
|||
* List Surfsense docs
|
||||
*/
|
||||
export const getSurfsenseDocsRequest = z.object({
|
||||
queryParams: paginationQueryParams
|
||||
queryParams: paginationQueryParams.extend({
|
||||
title: z.string().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const getSurfsenseDocsResponse = z.object({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue