I'm building a search for my Craft site right now.

Finding entries is fine. I usually have the structure that one entry is one site in the frontend.

I sadly also have entries that are way longer. So one entry of that can have 9 sites. When I search for something that is in this entry like with PHP

$results = \craft\elements\Entry::find()->search('example')->all();


$results = \craft\elements\MatrixBlock::find()->search('example')->all();

I get the full entry and get redirected to the first site of this entry. Same thing happens with GraphQL and the query:

  entries(search: "Example"){

My problem: I always get back the full entry, but not the exact MatrixBlock or the exact location of the word.

Is there any way to get the exact location (which entry and where in the entry) of the searched query? Either PHP or GraphQL is fine.

If there's no dynamic way to do that, is there a manual way to loop through the entry and find the exact MatrixBlock in PHP? If I'd do it in GraphQL I'd need to do too many requests and this wouldn't be handleable for the search to be dynamic.

Thanks in advance for any kind of help!

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.