fix(block-editor): support spaces in contentlet search (#34416)#35510
fix(block-editor): support spaces in contentlet search (#34416)#35510
Conversation
Tokenize the search filter on whitespace and emit one mandatory +catchall:*token* clause per token so multi-word queries (e.g. "White Water") narrow results to contentlets matching ALL tokens. Previously the unquoted space caused Lucene to parse the catchall as a single mandatory term + remaining optional terms, so multi-word filters degraded to filtering by only the first word. Also switch the title relevance boost from single quotes (literal, non-functional) to double quotes (Lucene phrase syntax). Empty filter now omits the catchall/title clauses entirely; hyphen-bearing filters preserve the existing identifier/UUID branch unchanged. Closes #34416
|
Claude finished @oidacra's task in 2m 38s —— View job PR Review
Issues1. UUID_LIKE regex silently kills searches for hex English words ( const UUID_LIKE = /^[0-9a-f]+(-[0-9a-f]+)+$/i;The comment claims it's "narrow enough to skip ordinary hyphenated English titles," but it matches any hyphen-separated sequence where every segment is all-hex. Short, real English words that are also valid hex: A proper UUID pattern ( 2. Hyphenated-word tokens won't match via wildcard ( When This existed before (the old 3. const identifierQuery = contentletIdentifier ? `-identifier:${contentletIdentifier}` : '';The PR adds Minor
|
Prettier flagged a double blank line left over from the previous import/order fix. nx format:check is now clean.
Address PR review on #34416: - Narrow the identifier/UUID branch from filter.includes('-') to a hex-only segmented pattern (UUID_LIKE). Hyphenated English titles like "self-care", "follow-up", or "White-Water Falls" now go through the regular tokenized search path instead of degrading to a non-wildcard exact-match clause. - Escape Lucene query-syntax characters (+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /) before interpolating user input into the catchall and title clauses, preventing a user from injecting arbitrary clauses that would bypass the +contentType restriction. - Drop the redundant .filter(token => token.length > 0) after .trim().split(/\s+/) — the regex already collapses interior runs and trim removes leading/trailing whitespace, so empty tokens are impossible. Adds tests for the hyphenated-title path, the injection-escaping behavior, and updates the existing UUID-branch assertion to expect the escaped hyphen.
Summary
Fixes the Block Editor contentlet search to support multi-word queries with spaces.
When typing inside the Block Editor's contentlet picker (after
/→ Contentlets → <ContentType>), spaces appear in the input but the result list does not refine. Root cause:SuggestionsService.getContentletsinterpolated the user filter into+catchall:*${filter}* title:'${filter}'^15. With a multi-word filter likeWhite Water, Lucene parses+catchall:*White Water*as two terms —+catchall:*White(mandatory) plusWater*(optional) — so the query degrades to a single-word filter on the first token only. The single-quoted title clause is also broken (Lucene phrase queries require double quotes).CleanShot.2026-04-29.at.17.32.41.mp4
Fix
In
suggestions.service.ts(getContentlets):+catchall:*token*clause per token, joined with spaces. Multi-word queries now require ALL tokens to match.title:'${filter}'^15totitle:"${filter}"^15for proper Lucene phrase semantics.identifierQuery) don't introduce double spaces.+catchall:${filter}, no wildcards).Closes
Closes #34416
Acceptance Criteria
White Water) narrows results to contentlets matching ALL tokens.-preserves the identifier branch.Test Plan
Automated tests added in
suggestions.service.spec.ts(now 8 tests, was 1) usingHttpTestingControllerto assert the exactquerystring sent to/api/content/_searchfor: multi-word, single-word, empty, whitespace-only, hyphen, andcontentletIdentifierexclusion cases, plus response mapping.Manual verification:
/, choose Contentlets → Activity.White Water— list filters to contentlets containing both words (e.g., White Water Rafting).Water— single-word search still works.Changed Files
core-web/libs/block-editor/src/lib/shared/services/suggestions/suggestions.service.tscore-web/libs/block-editor/src/lib/shared/services/suggestions/suggestions.service.spec.tscore-web/libs/block-editor/src/lib/elements/dot-bubble-menu/dot-bubble-menu.component.spec.ts(drive-by: 1-line import order fix to satisfynx affected:lint)Visual Changes
User-facing behavior change in the Block Editor contentlet search popup; the visual UI itself is unchanged. A before/after screen recording can be shared if needed.