What is the best way to query for a list of pdfs from the Media section with a specific property value (e.g. Category) and then display them in a View?
Should I use a Controller and the MediaService as I cannot find any examples using this method, or in fact, any other method.
Can someone please point me in the best direction?
The MediaService would be operating directly on the database and would be slow, it's meant to be for CRUD admin tasks, rather than being used to render things on the front end of your site.
If you go to the Settings section of your site and, click the Examine Management tab, you'll see a list of indexes for your site, if you click on the 'ExternalIndex' it will expand and you'll see a Search option, if you search for one of your PDFs, and then in the search results click on the green x Fields link... it will open up a panel showing all the information being held in the Examine Index for your Media Item.
You'll see __IndexType is set to media
When perform an Examine search you'll be able to use this to ljmit it to search Media only, similarly you can use umbracoExtension to restrict to PDFs, your picked 'category' mechanism should also be available here too...
Hopefully the documentation link above gets you started with how to perform an Examine query, it's super fast!
Thank you so much for your help.
This is exactly what I was searching for.
I have followed your instructions and the docs to create a SearchService which is perfect for my requirement.
Display a list of pdfs with a specific category
What is the best way to query for a list of pdfs from the Media section with a specific property value (e.g. Category) and then display them in a View?
Should I use a Controller and the MediaService as I cannot find any examples using this method, or in fact, any other method.
Can someone please point me in the best direction?
Thanks.
Hi Chris
All the Media is available to query via the Examine Search Indexes
https://docs.umbraco.com/umbraco-cms/reference/searching/examine/
The MediaService would be operating directly on the database and would be slow, it's meant to be for CRUD admin tasks, rather than being used to render things on the front end of your site.
If you go to the Settings section of your site and, click the Examine Management tab, you'll see a list of indexes for your site, if you click on the 'ExternalIndex' it will expand and you'll see a Search option, if you search for one of your PDFs, and then in the search results click on the green x Fields link... it will open up a panel showing all the information being held in the Examine Index for your Media Item.
You'll see __IndexType is set to media
When perform an Examine search you'll be able to use this to ljmit it to search Media only, similarly you can use umbracoExtension to restrict to PDFs, your picked 'category' mechanism should also be available here too...
Hopefully the documentation link above gets you started with how to perform an Examine query, it's super fast!
regards
Marc
Thank you so much for your help. This is exactly what I was searching for. I have followed your instructions and the docs to create a SearchService which is perfect for my requirement.
is working on a reply...