Search 3.0: Filter by Meta Field variation routes through jetpack-search-metaN slots (RSM-2819)#48688
Conversation
…rch-metaN slots (RSM-2819) Sibling of RSM-2108's Custom Taxonomy slot mapping — same architecture on the postmeta side of Jetpack Search's reserved slot mechanism. * Search_Blocks::custom_meta_map() reads a new jetpack_search_custom_meta_map filter that returns assoc [ 'user_key' => 'jetpack-search-metaN' ]; validation mirrors the taxonomy map (slot regex, dup detection, _doing_it_wrong notices). * Search_Blocks::resolve_meta_slot() returns the slot for mapped keys and the key verbatim for unmapped ones — called once at filterConfig build time so JS query builders stay pure. * Filter_Checkbox::build_config() now emits effectiveSlug for either filterType, routed through Search_Blocks::resolve_effective_slug(). filter-checkbox now also accepts filterType='meta', reusing the existing 'taxonomy' attribute as the facet-key carrier (saved-block disk shape stays single-attribute). * New 'Filter by Meta Field' variation in the inserter + matching inspector picker (sourced from JetpackSearchBlocksConfig.supportedCustomMetaKeys with '(mapped)' label suffix). * JS resolveFilterFields gains a 'meta' case targeting meta.<slot>.value.raw — the keyword sub-field the v1.3 Search API exposes for terms aggregations against the slot pool (verified empirically: meta.<slot>.value, .keyword, .raw, and the bare meta.<slot> all return 'unsupported field'). Verified end-to-end in atlas docker env: - Editor offers 'Filter by Meta Field' variation; picker shows mapped keys with '(mapped)' suffix. - A page with filter-checkbox(filterType=meta, taxonomy=author_role) saves with effectiveSlug=jetpack-search-meta1 on its filterConfig. - Front-end fetch URL hits meta.jetpack-search-meta1.value.raw, never meta.author_role.*; aggregation key stays user-facing as author_role.
This comment has been minimized.
This comment has been minimized.
|
Claude finished @kangzj's task in 2m 36s —— View job PR Review: RSM-2819 Meta Field Filter
Overall this is a high-quality PR. The design cleanly mirrors the taxonomy slot-mapping from RSM-2108, the validation is thorough, and the empirical ES field-path work is well documented. A few minor issues and test gaps worth addressing before merge. Issues1. Dummy third arg to
|
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
…strings, add tests - Search_Blocks::reset_custom_taxonomy_map_cache() → reset_custom_map_caches() (the method now also clears the meta-map cache; old name was misleading). - metaKeyOptions: the ternary's else branch was unreachable (supportedCustomMetaKeys === array_keys(customMetaMap)); simplified to always apply the (mapped) suffix and dropped the now-unused customMetaMap() helper from edit.js. - Replaced the dummy `0` third arg to __() in the meta-key help text with named const variables (metaKeyEmptyHelp / metaKeyPickHelp) so the i18n extraction stays clean. - New PHP test: Filter_Checkbox::build_config() with filterType='meta' pins effectiveSlug for mapped + unmapped keys and the reserved-param guard. - New JS test: variationToAttributes(VARIATION_FILTER_META) clears the carried taxonomy attribute regardless of the previous slug.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Claude finished @kangzj's task in 1m 36s —— View job Follow-up Review: RSM-2819 (4ad663a)
All five items from the previous review are addressed correctly. No new issues introduced. Fix verification#1 — i18n consts ( #2 — dead ternary removed ( #3 — method renamed ( #4 — PHP
#5 — JS variation-switch test ( One observation (non-blocking)
LGTM. All blocking items resolved, tests are solid, and the code is cleaner than before the review round. Happy to see this land. |
|
Claude finished @kangzj's task in 1m 21s —— View job Re-review: RSM-2819 Meta Field Filter (4ad663a)
All five items from the previous review are addressed cleanly. ✅ Fix #1 — Dummy
|
🤖 Review-cycle summary —
|
| Source | Item | Resolution |
|---|---|---|
| @claude (round 1) | Dummy 0 third arg to __() in meta-key help |
Hoisted to metaKeyEmptyHelp / metaKeyPickHelp consts (4ad663af140) |
| @claude (round 1) | Dead ternary in metaKeyOptions |
Simplified to always apply (mapped) suffix; dropped unused customMetaMap() reader (4ad663af140) |
| @claude (round 1) | reset_custom_taxonomy_map_cache() name misleading |
Renamed to reset_custom_map_caches() with updated docblock + tearDown caller (4ad663af140) |
| @claude (round 1) | Missing PHP test for meta build_config() path |
Added test_build_config_meta_filter_uses_effective_slug() (4ad663af140) |
| @claude (round 1) | Missing JS test for meta variation switch | Added variationToAttributes(VARIATION_FILTER_META) clear test (4ad663af140) |
Unaddressed (flagged for owner): none.
Stacked-PR note: this PR is based on atlas/rsm-2108-custom-taxonomy-whitelist (PR #48684). The base will swap to trunk once that lands; the diff against trunk at that point will be just the meta-mapping commits.
|
Claude finished @kangzj's task in 24s —— View job Review-Cycle AcknowledgedThanks for the clean cycle summary, @kangzj. All five review items were resolved in Status: LGTM 🟢 — ready to merge once PR #48684 (RSM-2108) lands and the base is swapped to |
|
@copilot resolve the merge conflicts in this pull request and fix linting error |
…hitelist' into atlas/rsm-2819-meta-mapping # Conflicts: # projects/packages/search/src/search-blocks/blocks/filter-checkbox/edit.js
Done — I merged the latest stacked base into this branch to resolve the conflict and fixed the lint/static-analysis failure ( Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
Parking this as we don't even have a meta filter yet. |
Fixes RSM-2819. Stacked on top of #48684 (RSM-2108) — base will swap to
trunkonce that lands.Why
Site owners who want to filter Jetpack Search results by an arbitrary postmeta value (e.g.
author_role,priority) have no way to do it today: the Search Blocks inserter only offers taxonomy / post-type / author filters, and Jetpack Search itself only indexes a curated set of meta keys. This PR adds a "Filter by Meta Field" block variation that uses the existingjetpack-search-meta0…jetpack-search-meta9reserved index slots — the same mechanism RSM-2108 (#48684) added for taxonomies — so the site owner declares a single mapping in PHP and the block then routes its aggregation against the right indexed field.Proposed changes
jetpack_search_custom_meta_map: assoc[ 'user_key' => 'jetpack-search-metaN' ]. Validation mirrors the taxonomy map (slot regex^jetpack-search-meta[0-9]$, duplicate-slot rejection,_doing_it_wrong()on misconfiguration / non-array return).Search_Blocks::resolve_meta_slot(): returns the slot for mapped keys, the key verbatim for unmapped ones. Resolution happens once at server-sideFilter_Checkbox::build_config()and travels with the filterConfig aseffectiveSlug— JS query builders stay pure (no global map argument).jetpack-search/filter-checkbox. Reuses the existingtaxonomyblock attribute as the facet-key carrier (the disk shape stays a single attribute;filterType: 'meta'disambiguates at query time). Inspector picker is sourced fromJetpackSearchBlocksConfig.supportedCustomMetaKeyswith a(mapped)label suffix.resolveFilterFieldsgains acase 'meta'that targetsmeta.<slot>.value.raw— the keyword sub-field the v1.3 Search API exposes for terms aggregations against the slot pool. Bucket format is'plain'(noslug/Namesplit like taxonomies have onslug_slash_name).Field path verification
The ES field path was determined empirically by probing the live v1.3 Search API with aggregations against each candidate sub-field on a known-indexed site (
en.blog.wordpress.com):meta.jetpack-search-meta0.value.rawmeta.jetpack-search-meta0.longmeta.jetpack-search-meta0.doublemeta.jetpack-search-meta0.value[aggs:…] unsupported field.meta.jetpack-search-meta0.keywordunsupported fieldmeta.jetpack-search-meta0.rawunsupported fieldmeta.jetpack-search-meta0(bare)unsupported fieldmeta.<nonsense>.value.raw(control)unsupported fieldFor terms aggregations (the string-facet path this PR exposes),
meta.<slot>.value.rawis the right answer. Numeric histogram / range against.long/.doubleis available but not used here — that's a follow-up if/when there's demand for numeric meta facets.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Drop this into
wp-content/mu-plugins/rsm-2819-test.phpon a Jetpack-Search-connected site:Then:
author_role (mapped)andpriority (mapped).meta.jetpack-search-meta1.value.raw(verify in DevTools network tab — the URL contains the slot field, notmeta.author_role.*).?author_role[]=foo; the aggregation response key staysaggregations[author_role]so no response-side normalization runs.Verified end-to-end in atlas docker env:
state.filterConfigs.author_role.effectiveSlug === 'jetpack-search-meta1', fetch URL targetsmeta.jetpack-search-meta1.value.rawand never leaksmeta.author_role.*.Unit tests: