@@ -35,8 +35,9 @@ export function useSearchResults(props: {
3535 siteSpaceIds : string [ ] ;
3636 scope : SearchScope ;
3737 withAI : boolean ;
38+ suggestions ?: string [ ] ;
3839} ) {
39- const { disabled, query, siteSpaceId, siteSpaceIds, scope } = props ;
40+ const { disabled, query, siteSpaceId, siteSpaceIds, scope, suggestions } = props ;
4041
4142 const trackEvent = useTrackEvent ( ) ;
4243
@@ -78,6 +79,22 @@ export function useSearchResults(props: {
7879 const questions = new Set < string > ( ) ;
7980 const recommendedQuestions : ResultType [ ] = [ ] ;
8081
82+ if ( suggestions && suggestions . length > 0 ) {
83+ suggestions . forEach ( ( question ) => {
84+ questions . add ( question ) ;
85+ } ) ;
86+ setResultsState ( {
87+ results : suggestions . map ( ( question , index ) => ( {
88+ type : 'recommended-question' ,
89+ id : `recommended-question-${ index } ` ,
90+ question,
91+ } ) ) ,
92+ fetching : false ,
93+ error : false ,
94+ } ) ;
95+ return ;
96+ }
97+
8198 const timeout = setTimeout ( async ( ) => {
8299 if ( cancelled ) {
83100 return ;
@@ -175,14 +192,14 @@ export function useSearchResults(props: {
175192 cancelled = true ;
176193 clearTimeout ( timeout ) ;
177194 } ;
178- } , [ query , scope , trackEvent , withAI , siteSpaceId , siteSpaceIds , disabled ] ) ;
195+ } , [ query , scope , trackEvent , withAI , siteSpaceId , siteSpaceIds , disabled , suggestions ] ) ;
179196
180197 const aiEnrichedResults : ResultType [ ] = React . useMemo ( ( ) => {
181198 if ( ! withAI ) {
182199 return resultsState . results ;
183200 }
184201 return withAskTriggers ( resultsState . results , query , assistants ) ;
185- } , [ resultsState . results , query , withAI ] ) ;
202+ } , [ resultsState . results , query , withAI , assistants ] ) ;
186203
187204 return { ...resultsState , results : aiEnrichedResults } ;
188205}
0 commit comments