Skip to content

Commit adbbe18

Browse files
authored
improvement(search): follow Jira summaries holding every term with those holding half of them (#9121)
* improvement(search): follow Jira summaries holding every term with those holding half of them * improvement(search): dedupe the Jira summary tiers and the all-terms page in one pass
1 parent 28eaf54 commit adbbe18

2 files changed

Lines changed: 34 additions & 16 deletions

File tree

‎apps/sim/lib/sim-search/live/atlassian.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,17 @@ describe('Jira plain search ranking', () => {
489489
const page = await searchAtlassian(api, 'jira', query)
490490
expect(page.documents.map((document) => document.id)[0]).toBe('HALF-9')
491491
})
492+
493+
it('follows summaries holding every term with those holding half of them', async () => {
494+
const api = jira(
495+
{ ids: ['NEW-3', 'NEW-2', 'NEW-1'], more: true },
496+
['ALL-1'],
497+
[
498+
{ key: 'ALL-1', summary: 'Merged results pipelines' },
499+
{ key: 'HALF-1', summary: 'Merged results dashboard' },
500+
]
501+
)
502+
const page = await searchAtlassian(api, 'jira', query)
503+
expect(page.documents.map((document) => document.id)).toEqual(['ALL-1', 'HALF-1', 'NEW-3'])
504+
})
492505
})

‎apps/sim/lib/sim-search/live/atlassian.ts‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ export async function searchAtlassian(
226226
next: exact.next,
227227
}
228228
// JQL has no relevance order, so an all-terms match larger than a page comes back newest
229-
// first; issues whose summary holds every term, or else at least half of three or more
230-
// terms (most terms first), lead it instead.
229+
// first; issues whose summary holds every term lead it instead, then those holding at
230+
// least half of three or more terms (most terms first).
231231
if (!text || input.native || order || input.textMatch === 'any' || !exact.next)
232232
return exactPage
233233
const terms = stemmedTerms(text)
@@ -241,22 +241,27 @@ export async function searchAtlassian(
241241
])
242242
// A cancelled search stops here; any other failure keeps the all-terms page.
243243
input.signal?.throwIfAborted()
244-
let titled =
244+
const everyTerm =
245245
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-
}
246+
const halfTerms =
247+
half.status === 'fulfilled' && half.value
248+
? half.value.issues
249+
.map(({ document, summary }) => ({ document, held: terms.held(summary) }))
250+
.filter(({ held }) => held >= terms.required)
251+
.sort((left, right) => right.held - left.held)
252+
.map(({ document }) => document)
253+
: []
254+
const titled = [...everyTerm, ...halfTerms]
253255
if (!titled.length) return exactPage
254-
const leading = new Set(titled.map((document) => document.id))
256+
const seen = new Set<string>()
255257
return {
256-
documents: [
257-
...titled,
258-
...exactPage.documents.filter((document) => !leading.has(document.id)),
259-
].slice(0, input.limit),
258+
documents: [...titled, ...exactPage.documents]
259+
.filter(({ id }) => {
260+
if (seen.has(id)) return false
261+
seen.add(id)
262+
return true
263+
})
264+
.slice(0, input.limit),
260265
excluded: false,
261266
ranking: 'relevance',
262267
}
@@ -323,7 +328,7 @@ export async function searchAtlassian(
323328
: '') +
324329
(pages.some((result) => result.ranking === 'relevance')
325330
? provider === 'jira'
326-
? ' More issues contained every word than fit on one page, so issues whose summary holds every word, or else most of them, come first; refine the query, or page with a native JQL query.'
331+
? ' More issues contained every word than fit on one page, so issues whose summary holds every word, then most of them, come first; refine the query, or page with a native JQL query.'
327332
: ' More pages contained every word than fit on one page, so this page is ordered by Confluence relevance search; refine the query, or page with a native CQL query.'
328333
: '') +
329334
(pages.some((result) => result.ranking === 'unavailable')

0 commit comments

Comments
 (0)