-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathsearchLimitExplanation.ts
More file actions
65 lines (57 loc) · 2.41 KB
/
searchLimitExplanation.ts
File metadata and controls
65 lines (57 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import type { SearchStats } from './types';
/** Values from zoekt `FlushReason` (grpc string enum names). */
const FLUSH_REASON_TIMER_EXPIRED = 'FLUSH_REASON_TIMER_EXPIRED';
const FLUSH_REASON_MAX_SIZE = 'FLUSH_REASON_MAX_SIZE';
/**
* User-facing copy when Zoekt returned a non-exhaustive search (more matches may exist
* than were returned or scanned).
*
* @see https://github.com/sourcebot-dev/sourcebot/issues/504
*/
export function getSearchLimitExplanation(
stats: SearchStats | undefined,
maxMatchDisplayCount: number,
): { summary: string; detail?: string } {
if (!stats) {
return {
summary: 'Results may be incomplete.',
detail: 'Increase the match limit, narrow your query, or scope to a repository.',
};
}
if (stats.shardsSkipped > 0) {
return {
summary: 'Search did not scan the entire index.',
detail: 'One or more index shards were skipped (often because the search hit a time limit). Additional matches may exist.',
};
}
if (stats.flushReason === FLUSH_REASON_TIMER_EXPIRED) {
return {
summary: 'Results were flushed early due to a streaming timer.',
detail: 'Try narrowing your query or increasing limits.',
};
}
if (stats.flushReason === FLUSH_REASON_MAX_SIZE) {
return {
summary: 'Intermediate result set reached its size limit.',
detail: 'Try narrowing your query or increasing limits.',
};
}
if (stats.totalMatchCount > maxMatchDisplayCount) {
return {
summary: 'More matches exist than are shown.',
detail: `The index reported ${stats.totalMatchCount} matches, but this request only returns up to ${maxMatchDisplayCount}. Use “load more” or raise the match limit.`,
};
}
if (stats.filesSkipped > 0) {
return {
summary: 'Some candidate files were not fully searched.',
detail: 'The engine stopped after finding enough matches (per-shard or total limits). Additional matches may exist.',
};
}
// Defensive fallback: non-exhaustive searches should usually hit a branch above
// (e.g. totalMatchCount vs display cap, skipped shards/files, or flush reason).
return {
summary: 'More matches may exist than are shown.',
detail: 'Increase the match limit, narrow your query, or scope to a repository.',
};
}