I'm successfully using the .search element attribute to search asset filenames stored locally.
{% set mediaExists = craft.assets.folderId('6').search('filename:' ~ vLogID|slice(0, 5)) %}
Is it possible to search filenames stored on a remote Amazon S3 volume?
In my testing, it doesn't seem to be finding the remote files. It works when searching the local volume folderId('3') by not when the remote S3 folder folderId('6').
Background: There is no direct relationship between an entry and assets. I upload all assets to the server via FTP and then index the volume in my Craft Control Panel. I can see the S3 asset in Craft CP and have cleared cache and reindexed the S3 folder source.
I am using a url query string to tell the template what the LogID is for the entry that is displayed. Then, the code searches the asset folder for any assets that contain that LogID number. If there are any matches, then those assets are displayed on the front end page in a slider.
I can see the S3 asset if I type in the direct asset url link so the permissions of Public seem to be set correctly.
This is my code that is searching the asset filename on the server:
<!-- grab log id and use slice filter -->
{% set vLogID = craft.app.request.segments|last %}
<!-- Check to see if there is any media uploaded -->
{% set mediaExists = craft.assets.folderId('6').search('filename:' ~ vLogID|slice(0, 5)) %}
The above code says:
Grab the LogID from the url query string (example: 12345).
Then, search the asset folder (set by folderID), search all of the files in the folder for any filenames that contain LogID (example 12345).
It works when searching the local volume folderId('3') but not when the remote S3 folder folderId('6').
.search()
, it's actually searching against thesearchindex
table in the database. If you search that table, do you see the filename as a search keyword for what you're searching for? Also, what is the filename?