Is it possible to display an entry field in search results if it contains the search query?
Context: I have an entry with a list of PDF assets. I want to show an asset in the search results if it contains the search query in the asset title. By default all the asset titles would display if any one contains the search query.
This is what I have in mind:
{% set searchQuery = craft.app.request.getParam('q') %}
{% set entries = craft.entries
.section([
'and', 'resources'
])
.search(searchQuery)
.orderBy('score')
.all() %}
{% if entries|length %}
<ul>
{% for entry in entries %}
<li><a href="{{ entry.url }}">{{ entry.title }}</a><br>
{% set block = entry.downloads.all() %}
{% if block|length %}
{% for file in block %}
{% for asset in file.file.all() %}
{% if asset ***CONTAINS SEARCHQUERY*** %}
{{ asset.title }}
{% endif %}
{% endfor %}<br>
{% endfor %}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}