File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -491,3 +491,18 @@ export async function fetchTagsThatMatchKeyword({
491
491
492
492
return { matches : Array . from ( matches ) . map ( ( tagPath ) => ( { tagPath } ) ) , mayBeMissingResults : hits . length === limit } ;
493
493
}
494
+
495
+ /**
496
+ * Fetch single document by its id
497
+ */
498
+ export async function fetchDocumentById ( { client, indexName, id } : {
499
+ /** The Meilisearch client instance */
500
+ client : MeiliSearch ;
501
+ /** Which index to search */
502
+ indexName : string ;
503
+ /** document id */
504
+ id : string | number ;
505
+ } ) : Promise < ContentHit | CollectionHit > {
506
+ const doc = await client . index ( indexName ) . getDocument ( id ) ;
507
+ return formatSearchHit ( doc ) ;
508
+ }
Original file line number Diff line number Diff line change @@ -240,3 +240,26 @@ export const useTagFilterOptions = (args: {
240
240
241
241
return { ...mainQuery , data } ;
242
242
} ;
243
+
244
+ export const useGetSingleDocument = ( { client, indexName, id } : {
245
+ client ?: MeiliSearch ;
246
+ indexName ?: string ;
247
+ id : string | number ;
248
+ } ) => (
249
+ useQuery ( {
250
+ enabled : client !== undefined && indexName !== undefined ,
251
+ queryKey : [
252
+ 'content_search' ,
253
+ client ?. config . apiKey ,
254
+ client ?. config . host ,
255
+ indexName ,
256
+ id ,
257
+ ] ,
258
+ queryFn : ( ) => {
259
+ if ( client === undefined || indexName === undefined ) {
260
+ throw new Error ( 'Required data unexpectedly undefined. Check "enable" condition of useQuery.' ) ;
261
+ }
262
+ return fetchDocumentById ( { client, indexName, id } ) ;
263
+ } ,
264
+ } )
265
+ )
You can’t perform that action at this time.
0 commit comments