Answers.Body: <p>You can use <code>craft.assets()</code> to search for assets, the same way you can use <code>craft.entries()</code> to find entries. See <a href="https://craftcms.com/docs/3.x/assets.html#querying-assets" rel="nofollow noreferrer">Querying Assets</a> for details. Asset queries allow you to use mostly the same methods that entry queries do. For example, you can also use the <a href="https://craftcms.com/docs/3.x/assets.html#search" rel="nofollow noreferrer"><code>.search</code> method</a> to search for keywords in the asset's title and searchable fields.</p>
  <pre><code>{% set searchQuery = craft.app.request.getQueryParam('q') %}
  
  {% set foundAssets = craft.assets()
      .search(searchQuery)
      .all()
  %}
  </code></pre>
  <p>Limiting the search to assets that are selected on a specific entry can be done using the <a href="https://craftcms.com/docs/3.x/relations.html" rel="nofollow noreferrer">relatedTo</a> method:</p>
  <pre><code>{% set downloadsPage = craft.entries().section('downloads').one() %}
  {% set foundAssets = craft.assets()
      .search(searchQuery)
      .relatedTo(downloadsPage)
      .all()
  %}
  </code></pre>
  <p>See the documentation linked above for more information (for example, how to limit the relation to a specific field and direction).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-17T14:08:25.303Z
Answers.LastActivityDate: 2021-09-17T14:08:25.303Z
Answers.UserDisplayName: MoritzLost
Body: <p>I build a search component, and it works fine.
  Now I would like to show all the uploaded assets from a specific page (&quot;Downloads&quot;) in the search results that include the search key.</p>
  <p>How can I do that with Craft?</p>
  
Tags: <craft3><search>
Title: Search query for assets
ThreadText: # Search query for assets
  
  (Asked by: username_0 on 2021-09-17)
  
  I build a search component, and it works fine.
  Now I would like to show all the uploaded assets from a specific page ("Downloads") in the search results that include the search key.
  
  How can I do that with Craft?
  
  **Tags:** craft3, search
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-09-17. Score: 2 | Accepted answer
  
  You can use `craft.assets()` to search for assets, the same way you can use `craft.entries()` to find entries. See [Querying Assets](https://craftcms.com/docs/3.x/assets.html#querying-assets) for details. Asset queries allow you to use mostly the same methods that entry queries do. For example, you can also use the [`.search` method](https://craftcms.com/docs/3.x/assets.html#search) to search for keywords in the asset's title and searchable fields.
  
  ```
  {% set searchQuery = craft.app.request.getQueryParam('q') %}
  
  {% set foundAssets = craft.assets()
      .search(searchQuery)
      .all()
  %}
  
  ```
  
  Limiting the search to assets that are selected on a specific entry can be done using the [relatedTo](https://craftcms.com/docs/3.x/relations.html) method:
  
  ```
  {% set downloadsPage = craft.entries().section('downloads').one() %}
  {% set foundAssets = craft.assets()
      .search(searchQuery)
      .relatedTo(downloadsPage)
      .all()
  %}
  
  ```
  
  See the documentation linked above for more information (for example, how to limit the relation to a specific field and direction).
  
  
  ---
  
  