Skip to content

Patterns: Combine local and w.org search results for Inserter #28248

@iandunn

Description

@iandunn

#26578 is adding an API endpoint to fetch patterns from the w.org pattern directory. Plugins can also create local patterns via register_block_pattern() too. When the Inserter displays pattern search results, it'll need to combine local and remote patterns.

I'm not sure how they should be sorted, though. The remote patterns will have high-quality ElasticSearch rankings, but the local patterns will have low-quality MySQL rankings.

Normalized scores

Is it possible normalize the relevance scores from MySQL and ElasticSearch?

If so, we could simply sort them by the score, and maybe weight local ones a bit higher? We'd need to make sure Jetpack/ES returns the score along w/ the results (related tellyworth/plugin-directory#1)

ElasticSearch & Privacy

We could potentially pass the local patterns to the w.org API, so that ElasticSearch can rank them all.

That raises some potential privacy concerns, though, especially since ES is done on Automattic servers (via Jetpack Search). I don't imagine there'd be much sensitive content in most, but some custom patterns might reveal something about a site's content, or have placeholder content that reveals something sensitive.

We could add a filter to disable passing local patterns to w.org, and/or add a private={true | false} parameter to register_block_pattern(). If that were disabled, we'd have to have some fallback mechanism for sorting.

w.org wouldn't have any interest in using that data for anything other than sorting, so we could avoid storing it. It'd probably be desirable from a technical/performance standpoint to store them (semi?-)permanently, though.

cc @mrxkon, @birgire, @postphotos for feedback

Other Solutions

  • Maybe the UI should show them separately? We'll need some feedback from a designer.
  • Maybe they'd just be tacked on to the beginning or end of the list?

Tasks

  • Combine local patterns when browsing
  • Adjust sanitization/validation so that local patterns can add JS, unfiltered HTML, etc if they want?
  • Combine local patterns when searching

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] PatternsA collection of blocks that can be synced (previously reusable blocks) or unsynced[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions