Search by

youngdogs / magento2-cms-search

JavierYDyoungdogs

Adds flexible GraphQL search for CMS pages and CMS blocks (search by content, title, content_heading, and more, with word and exact-phrase matching).

Package info

github.com/Young-dogs/magento2-cms-search

Type:magento2-module

pkg:composer/youngdogs/magento2-cms-search

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.1 2026-09-01 09:34 UTC

This package is auto-updated.

Last update: 2026-09-18 09:43:59 UTC


README

Adds flexible GraphQL search for Magento 2 CMS pages and CMS blocks.

Out of the box, Magento only lets you fetch a CMS page by its exact identifier, or CMS blocks by an exact list of identifiers. This module adds two additional queries, cmsPageSearch and cmsBlockSearch, that let you search by content, title, and other fields — with exact match, word/phrase search, or "in list" filtering.

Requirements

  • PHP 8.2 - 8.5
  • Magento 2.4.6+
  • Magento_Cms, Magento_Store, Magento_GraphQl (installed by default with Magento)

Installation

composer require youngdogs/magento2-cms-search
bin/magento module:enable YoungDogs_CmsSearch
bin/magento setup:upgrade
bin/magento cache:flush

Configuration

Stores > Configuration > YOUNG-DOGS > CMS Search

The section is protected by the Stores > Configuration > CMS Search ACL permission.

Field Description
Enable module Yes/No, defaults to Yes. When disabled, both queries return a GraphQL input error.
Maximum Page Size Hard upper limit applied to pageSize, regardless of what the client requests.

Only active pages/blocks belonging to the current store view are returned.

GraphQL usage

Search CMS pages

{
  cmsPageSearch(
    filter: {
      content: { match: "\"free shipping\" promo" }
      identifier: { in: ["about-us", "contact-us"] }
    }
    pageSize: 10
    currentPage: 1
    sort: { field: TITLE, direction: ASC }
  ) {
    items {
      identifier
      title
      content
      content_text
      content_heading
      page_layout
      meta_title
      meta_description
      meta_keywords
    }
    total_count
    page_info {
      page_size
      current_page
      total_pages
    }
  }
}

Search CMS blocks

{
  cmsBlockSearch(filter: { title: { match: "homepage banner" } }) {
    items {
      identifier
      title
      content
      content_text
    }
    total_count
    page_info {
      page_size
      current_page
      total_pages
    }
  }
}

Filterable fields

Query Fields
cmsPageSearch identifier, title, content, content_heading, meta_title, meta_description, meta_keywords
cmsBlockSearch identifier, title, content

Each field accepts a CmsSearchFilterTypeInput:

Condition Behavior
eq Exact match.
in Matches any value in the given array.
match Search-engine style: "quoted phrases" are matched literally; remaining words are split on whitespace and combined with AND. Case-insensitive substring match.

Multiple fields in the same filter object are combined with AND.

Plain-text content

Both cmsPageSearch and cmsBlockSearch items expose a content_text field alongside content: the same content with HTML tags, <script>/<style> blocks, and entities stripped/decoded, leaving plain readable text. Useful when passing results to an AI agent that shouldn't have to parse markup.

Sorting

sort: { field: TITLE | IDENTIFIER, direction: ASC | DESC } (defaults to title ASC).

Limitations

  • match performs a LIKE-based substring search (no fulltext/relevance engine dependency required). For very large CMS catalogs, consider indexing content externally (e.g. Elasticsearch/OpenSearch) if search performance becomes a concern.
  • Only active pages/blocks are searchable; there is no admin/preview mode for inactive content.

License

MIT — see LICENSE.