File tree Expand file tree Collapse file tree 3 files changed +85
-2
lines changed
packages/plugin-search/src Expand file tree Collapse file tree 3 files changed +85
-2
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ export type SanitizedSearchPluginConfig = {
8484
8585export type SyncWithSearchArgs = {
8686 collection : string
87- pluginConfig : SearchPluginConfig
87+ pluginConfig : SanitizedSearchPluginConfig
8888} & Omit < Parameters < CollectionAfterChangeHook > [ 0 ] , 'collection' >
8989
9090export type SyncDocArgs = {
Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ export const syncDocAsSearchIndex = async ({
2424 } ,
2525 title,
2626 }
27- const docKey = `${ collection } :${ id } `
27+ const docKeyPrefix = `${ collection } :${ id } `
28+ const docKey = pluginConfig . locales ?. length ? `${ docKeyPrefix } :${ syncLocale } ` : docKeyPrefix
2829 const syncedDocsSet = ( req . context ?. syncedDocsSet as Set < string > ) || new Set < string > ( )
2930
3031 if ( syncedDocsSet . has ( docKey ) ) {
Original file line number Diff line number Diff line change @@ -589,6 +589,88 @@ describe('@payloadcms/plugin-search', () => {
589589 )
590590 } )
591591
592+ it ( 'should reindex all configured locales' , async ( ) => {
593+ const post = await payload . create ( {
594+ collection : postsSlug ,
595+ locale : 'en' ,
596+ data : {
597+ title : 'Test page published' ,
598+ _status : 'published' ,
599+ slug : 'test-en' ,
600+ } ,
601+ } )
602+ await payload . update ( {
603+ collection : postsSlug ,
604+ id : post . id ,
605+ locale : 'es' ,
606+ data : {
607+ _status : 'published' ,
608+ slug : 'test-es' ,
609+ } ,
610+ } )
611+ await payload . update ( {
612+ collection : postsSlug ,
613+ id : post . id ,
614+ locale : 'de' ,
615+ data : {
616+ _status : 'published' ,
617+ slug : 'test-de' ,
618+ } ,
619+ } )
620+
621+ const {
622+ docs : [ postBeforeReindex ] ,
623+ } = await payload . find ( {
624+ collection : 'search' ,
625+ locale : 'all' ,
626+ where : {
627+ doc : {
628+ equals : {
629+ value : post . id ,
630+ relationTo : postsSlug ,
631+ } ,
632+ } ,
633+ } ,
634+ pagination : false ,
635+ limit : 1 ,
636+ depth : 0 ,
637+ } )
638+
639+ expect ( postBeforeReindex ?. slug ) . not . toBeFalsy ( )
640+
641+ const endpointRes = await restClient . POST ( `/search/reindex` , {
642+ body : JSON . stringify ( {
643+ collections : [ postsSlug ] ,
644+ } ) ,
645+ headers : {
646+ Authorization : `JWT ${ token } ` ,
647+ } ,
648+ } )
649+
650+ expect ( endpointRes . status ) . toBe ( 200 )
651+
652+ const {
653+ docs : [ postAfterReindex ] ,
654+ } = await payload . find ( {
655+ collection : 'search' ,
656+ locale : 'all' ,
657+ where : {
658+ doc : {
659+ equals : {
660+ value : post . id ,
661+ relationTo : postsSlug ,
662+ } ,
663+ } ,
664+ } ,
665+ pagination : false ,
666+ limit : 1 ,
667+ depth : 0 ,
668+ } )
669+
670+ expect ( postAfterReindex ?. slug ) . not . toBeFalsy ( )
671+ expect ( postAfterReindex ?. slug ) . toStrictEqual ( postBeforeReindex ?. slug )
672+ } )
673+
592674 it ( 'should sync trashed documents correctly with search plugin' , async ( ) => {
593675 // Create a published post
594676 const publishedPost = await payload . create ( {
You can’t perform that action at this time.
0 commit comments