Search for assets containing a custom field How can I search for assets containing a custom field? The field on the asset is called lang. When I use this code no assets are found.
{% set folderId = craft.app.request.getQueryParam('folderId') %}
{% set query = craft.app.request.getQueryParam('q') %}
{% set lang = craft.app.request.getQueryParam('lang') %}

{# Search for assets in the downlaoads folder #}
{% set assets = craft.assets().volume('downloads') %}
{% set assets = assets.folderId(folderId).includeSubFolders() %}

{% set searchQuery = [] %}

{# Check if a query was supplied, if so then search for it. #}
{% if query is not empty %}
{%     set searchQuery = searchQuery|merge({query: query}) %}
{% endif %}

{% if lang is not empty %}
{%   set searchQuery = searchQuery|merge({query: 'lang:' ~ lang}) %}
{% endif %}

{% paginate assets.search(searchQuery).limit(10) as pageInfo, pageEntries %}
I also tried:
{% set query = query ~ ' lang: ' ~lang %}
{% paginate assets.search(query).limit(10) as pageInfo, pageEntries %}

If I remove the lang part results will show up.
The field is a Dropdown field with languages. Value is ISO code and Label the language name. The variable lang in the code contains nl, en etc.
Caveat: This is totally untested, and could be nonsense. I'm sure you'll let me know. It assumes that the Craft element query methods can be used here.
If you have a 'lang' value, add a where to your basic assets element query
    {% set folderId = craft.app.request.getQueryParam('folderId') %}
    {% set query = craft.app.request.getQueryParam('q') %}
    {% set lang = craft.app.request.getQueryParam('lang') %}
    
    {# Search for assets in the downloads folder #}
    {% set assetsQuery = craft.assets().volume('downloads') %}
    {% set assetsQuery = assets.folderId(folderId).includeSubFolders() %}

    {# If there's a lang value, add a where to the element query #}
    {% if lang is not empty %}
    {%     set assetsQuery = assetsQuery.where(expression('[[field_lang]] = :lang', {lang: lang})) %}
    {% endif %}
    
    {% set searchQuery = [] %}

    {# Check if a query was supplied, if so then search for it. #}
    {% if query is not empty %}
    {%     set searchQuery = searchQuery|merge({query: query}) %}
    {% endif %}
    
    {% paginate assetsQuery.search(searchQuery).limit(10) as pageInfo, pageEntries %}

*Note that I've changed the variable 'assets' to 'assetsQuery'