Skip to content

Commit f568b95

Browse files
committed
fix: include final trigram in search matching
add regression test asserting long queries require their trailing trigram adjust trigram loop to cover the last trigram so partial matches stop passing
1 parent afce04c commit f568b95

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

plugins/toolbox-search/src/block_searcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class BlockSearcher {
113113
if (normalizedInput.length <= 3) return [normalizedInput];
114114

115115
const trigrams: string[] = [];
116-
for (let start = 0; start < normalizedInput.length - 3; start++) {
116+
for (let start = 0; start <= normalizedInput.length - 3; start++) {
117117
trigrams.push(normalizedInput.substring(start, start + 3));
118118
}
119119

plugins/toolbox-search/test/tests.mocha.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ suite('BlockSearcher', () => {
5757
assert.sameMembers(ransomNoteMatches, [listCreateWithBlock]);
5858
});
5959

60+
test('requires the final trigram when matching longer queries', () => {
61+
const searcher = new BlockSearcher();
62+
const mathConstrainBlock = {
63+
kind: 'block',
64+
type: 'math_constrain',
65+
};
66+
searcher.indexBlocks([mathConstrainBlock]);
67+
68+
const matches = searcher.blockTypesMatching('conso');
69+
70+
assert.notInclude(
71+
matches,
72+
mathConstrainBlock,
73+
'query missing trailing trigram should not match',
74+
);
75+
});
76+
6077
test('returns an empty list when no matches are found', () => {
6178
const searcher = new BlockSearcher();
6279
assert.isEmpty(searcher.blockTypesMatching('abc123'));

0 commit comments

Comments
 (0)