@@ -118,8 +118,9 @@ async function sites(client: NativeClient) {
118118}
119119
120120/**
121- * Pair matches fetched for the half-the-terms summary fallback; the page is filtered to summaries
122- * holding enough terms, so it starts from a wider pool than the caller's limit.
121+ * Pair matches fetched for the half-the-terms summary fallback. Jira returns them newest first,
122+ * not by relevance, and the page is then filtered to summaries holding enough terms, so it starts
123+ * from a wider pool than the caller's limit or the any-term fallback's.
123124 */
124125const HALF_TERM_CANDIDATES = 50
125126
@@ -182,8 +183,11 @@ export async function searchAtlassian(
182183 const cloudId = string ( site . id )
183184 const origin = string ( site . url ) . replace ( / \/ $ / , '' )
184185 if ( provider === 'jira' ) {
185- /** One JQL page, each issue with its summary and description. */
186- const searchIssues = async ( jql : string , cursor ?: string , maxResults = input . limit ) => {
186+ /** One JQL page, each issue with its summary and raw fields. */
187+ const searchIssues = async (
188+ jql : string ,
189+ { cursor, maxResults = input . limit } : { cursor ?: string ; maxResults ?: number } = { }
190+ ) => {
187191 const data = object (
188192 await client . json ( `/ex/jira/${ segment ( cloudId ) } /rest/api/3/search/jql` , {
189193 body : {
@@ -201,20 +205,21 @@ export async function searchAtlassian(
201205 return {
202206 document : issue ( row , cloudId , origin ) ,
203207 summary : string ( fields . summary ) ,
204- description : textContent ( fields . description ) ,
208+ fields,
205209 }
206210 } ) ,
207211 next : string ( data . nextPageToken ) || undefined ,
208212 }
209213 }
210214 const exact = await searchIssues (
211215 input . native ?. query || ( text ? jiraTextClause ( text , input . textMatch ) : '' ) ,
212- input . native ?. cursor && single ? input . native . cursor : undefined
216+ { cursor : input . native ?. cursor && single ? input . native . cursor : undefined }
213217 )
214218 const exactPage : SitePage = {
215219 documents : exact . issues
216220 . filter (
217- ( { summary, description } ) => ! relevant || relevant ( `${ summary } \n${ description } ` )
221+ ( { summary, fields } ) =>
222+ ! relevant || relevant ( `${ summary } \n${ textContent ( fields . description ) } ` )
218223 )
219224 . map ( ( { document } ) => document ) ,
220225 excluded : false ,
@@ -229,22 +234,22 @@ export async function searchAtlassian(
229234 const [ every , half ] = await Promise . allSettled ( [
230235 searchIssues ( jiraTextClause ( text , 'all' , 'summary' ) ) ,
231236 terms . count >= 3
232- ? searchIssues ( jiraTextClause ( text , 'any' , 'summary' ) , undefined , HALF_TERM_CANDIDATES )
237+ ? searchIssues ( jiraTextClause ( text , 'any' , 'summary' ) , {
238+ maxResults : HALF_TERM_CANDIDATES ,
239+ } )
233240 : undefined ,
234241 ] )
235242 // A cancelled search stops here; any other failure keeps the all-terms page.
236243 input . signal ?. throwIfAborted ( )
237- const required = Math . ceil ( terms . count / 2 )
238- const titled =
239- every . status === 'fulfilled' && every . value . issues . length
240- ? every . value . issues . map ( ( { document } ) => document )
241- : half . status === 'fulfilled' && half . value
242- ? half . value . issues
243- . map ( ( { document, summary } ) => ( { document, held : terms . held ( summary ) } ) )
244- . filter ( ( { held } ) => held >= required )
245- . sort ( ( left , right ) => right . held - left . held )
246- . map ( ( { document } ) => document )
247- : [ ]
244+ let titled =
245+ every . status === 'fulfilled' ? every . value . issues . map ( ( { document } ) => document ) : [ ]
246+ if ( ! titled . length && half . status === 'fulfilled' && half . value ) {
247+ titled = half . value . issues
248+ . map ( ( { document, summary } ) => ( { document, held : terms . held ( summary ) } ) )
249+ . filter ( ( { held } ) => held >= terms . required )
250+ . sort ( ( left , right ) => right . held - left . held )
251+ . map ( ( { document } ) => document )
252+ }
248253 if ( ! titled . length ) return exactPage
249254 const leading = new Set ( titled . map ( ( document ) => document . id ) )
250255 return {
0 commit comments