mirror of
https://github.com/docmost/docmost.git
synced 2025-11-19 05:41:08 +10:00
feat(EE): full-text search in attachments (#1502)
* feat(EE): fulltext search in attachments * feat: global search - search filters - attachments search ui - and more * fix import * fix import * rename migration * add GIN index * fix table name * sanitize
This commit is contained in:
42
apps/client/src/features/search/hooks/use-unified-search.ts
Normal file
42
apps/client/src/features/search/hooks/use-unified-search.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { useQuery, UseQueryResult } from "@tanstack/react-query";
|
||||
import {
|
||||
searchPage,
|
||||
searchAttachments,
|
||||
} from "@/features/search/services/search-service";
|
||||
import {
|
||||
IAttachmentSearch,
|
||||
IPageSearch,
|
||||
IPageSearchParams,
|
||||
} from "@/features/search/types/search.types";
|
||||
import { useLicense } from "@/ee/hooks/use-license";
|
||||
|
||||
export type UnifiedSearchResult = IPageSearch | IAttachmentSearch;
|
||||
|
||||
export interface UseUnifiedSearchParams extends IPageSearchParams {
|
||||
contentType?: string;
|
||||
}
|
||||
|
||||
export function useUnifiedSearch(
|
||||
params: UseUnifiedSearchParams,
|
||||
): UseQueryResult<UnifiedSearchResult[], Error> {
|
||||
const { hasLicenseKey } = useLicense();
|
||||
|
||||
const isAttachmentSearch =
|
||||
params.contentType === "attachment" && hasLicenseKey;
|
||||
const searchType = isAttachmentSearch ? "attachment" : "page";
|
||||
|
||||
return useQuery({
|
||||
queryKey: ["unified-search", searchType, params],
|
||||
queryFn: async () => {
|
||||
// Remove contentType from backend params since it's only used for frontend routing
|
||||
const { contentType, ...backendParams } = params;
|
||||
|
||||
if (isAttachmentSearch) {
|
||||
return await searchAttachments(backendParams);
|
||||
} else {
|
||||
return await searchPage(backendParams);
|
||||
}
|
||||
},
|
||||
enabled: !!params.query,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user