1

I'm using a Matrix field as a content builder, allowing the editor to freely create content blocks, titles, images, etc, etc. All of which is content that is required to be searched. But also included in there is an entries fields allowing the editor to select related content to appear within the page content. Because the search control ("Use this field’s values as search keywords?") is on the whole Matrix field, this related field is also getting scooped up in the indexing, which means entries are appearing in search results based on their related entries content, not their content.

Is there a way to exclude from search a specific block/field type from within a Matrix field? Or exclude related entries?

Possibly enhancing the search query (current code below)...?

        {% set searchResults = craft.entries()
            .section('articles')
            .search(searchQuery)
            .slug('and, not __home__')
            .orderBy('score')
            .all() %}

Or a way to parse the results without it dragging down performance? Although this will render score useless.

The other option I've considered is to rebuild the whole site moving the content to utilise Neo fields which might allow search control specific to each field within the Neo Matrix (need to explore & confirm).

Here's the Matrix field, the linkedContent and globalBlock are the offending fields polluting the search, but can't be removed from the Matrix, as then they wouldn't be able to be placed into the middle of content pages.

enter image description here

Update 1: Tried editing the database fields table, changing the individual field's "searchable" column to false and re-indexed but assume it's ignored (or just honors the parent Matrix field setting), as search results still include the offending entries field.

Update 2: Leading on from previous update, I explored the code and it is a minor amend to the Matrix field code to enable/disable searching of individual blocks within the Matrix. I've posted a bug fix/change request here which also includes the partial solution.

  • Hmm good point - you should create an issue on GitHub asking for them to add checkboxes or some other way of excluding fields within Matrix fields from being included in the search results -> github.com/craftcms/cms/issues – Jalen Davenport May 21 '19 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.