1

I have a frontend search form and I want to search within a matrix block. I have checked the box to make this field searchable. enter image description here

And I'm using the expanded search plugin.

Here is my results code

{% set query = craft.app.request.getParam('q') %}

  {% set expandedResults = craft.expandedSearch.search(query) %}
  {% for result in expandedResults %}
      <strong data-field="{{result.matchedField}}">{{result.entry.title}}</strong><br>
      <p>{{result.matchedValue}}</p>
      <a href="{{result.entry.url}}">{{result.entry.url}}</a>
  {% else %}
      <p>Sorry, no results for {{query}}.</p>
  {% endfor %}

Now if I try to search for a specific word from my content, the search result shows only the Entries that have the query word in their title, but not inside content.

4
  • Have you marked both the field inside the matrix as well as the matrix field itself as searchable?
    – MoritzLost
    Aug 11 at 11:22
  • Actually I didn't do that, but I did it just now, but the search still doesn't work. I would also expect to have a search reindex, but I don't see that.
    – loliki
    Aug 11 at 11:34
  • 1
    Not sure if the search index is updated automatically when changing settings. You can use the resave command to save all entries, forcing an update to the search index: php craft resave/entries --update-search-index. Also, search indexes are updated asynchronously using a queue job, so make sure you have a queue listener active on your development machine so the queue jobs are actually processed.
    – MoritzLost
    Aug 11 at 12:41
  • 1
    Perfect, thanks a lot, now everything works fine :)
    – loliki
    Aug 11 at 19:00
2

To make fields inside matrix blocks searchable, you need to check Use this field’s values as search keywords? both for the fields inside the matrix as well as for the matrix field itself. Your screenshot only shows the checkbox checked for a nested field, so make sure the matrix field is searchable as well. If the matrix field itself is not searchable, setting the fields inside it to searchable won't have any effect.

From the documentation:

For Matrix fields, the top-level Use this field’s values as search keywords setting determines whether any sub-fields will factor into results for the parent. For relational fields like Assets, Categories, and Entries, the setting determines whether related titles should factor into search results.

Source

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.