Skip to content

Toolbox search: long queries drop the last trigram, causing false positives (e.g. “conso” matches “math constrain”) #2645

@goughjo02

Description

@goughjo02

Check for duplicates

  • I have searched for similar issues before opening a new one.

Component

toolbox-search plugin (plugins/toolbox-search), version 3.1.3 (current main)

Description

When searching in the toolbox search category, queries longer than three characters can match blocks that don’t contain the full query. Example: typing “conso” returns the built-in math_constrain block even though its text is “math constrain”. The trigram generator in src/block_searcher.ts stops one character early:

for (let start = 0; start < normalizedInput.length - 3; start++)

so “conso” produces only ["con", "ons"] (missing nso). Because matches are the intersection of generated trigrams, dropping the final trigram broadens results and yields false positives. Expected: include the final trigram (loop should use <=), so “conso” would not match “math constrain”.

I’m happy to work on a fix; the minimal change is to adjust the trigram loop in src/block_searcher.ts to include the final trigram (<= normalizedInput.length - 3).

Reproduction steps

  1. Install @blockly/toolbox-search and include a toolbox that contains the default math blocks (so math_constrain is present).
  2. Add the search category to the toolbox: { kind: 'search', name: 'Search', contents: [] }.
  3. Open the search category and type conso.
  4. Observe that math_constrain appears in the results.

Expected result
No matches for “conso” unless a block actually contains that substring.

Actual result
math_constrain (and any block with “con”+“ons” but not the full “conso”) appears.

Stack trace

Screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedOpen for contributionstype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions