Do you want the full path for the media nodes to be displayed on the search result? Or is it in Umbraco you're in doubt about how you select the media node? Or do you just need to know how to write out the path for the file with XSLT?
As per the example I put in my post, the search result (from a Google Search Appliance as XML) is returning the physical path to the PDF. I want to find that PDF in the media library so that I can get the name given to it in the media library - rather than the physical file name.
Unfortunately, the number in the path which relates to the folder that contains the PDF is not the ID of the Media Library node. I cannot see any builtin Umbraco functions that will allow me to get the Media Library node and hence name.
I have investigated the database and found a way of locating the node ID, but it is not a solution I like.
This is a crude way to do it, mainly because it forces you to collect all the Media items' XML into a variable, but once you've got that it's really a walk in the park (or on the 'X Path' so to speak :-)
If you've got all the PDFs in a single folder, for God's sake use that folder's ID as the MEDIA_NODE_ID.
<!-- Fetch ALL media items below MEDIA_NODE_ID: -->
<xsl:variable name="media" select="umbraco.library:GetMedia(MEDIA_NODE_ID, true())" />
<!-- Sample result -->
<xsl:variable name="pdfFileName" select="'/media/1057/Season-4_Episode-5_The-Constant.pdf'" />
<!-- Find the File... -->
<xsl:apply-templates select="$media//File[substring-after(umbracoFile, '/media/') = substring-after($pdfFileName, '/media/')]" />
<!-- Reusable template for File elements -->
<xsl:template match="File">
<p class="result">
<a href="{umbracoFile}" type="application/pdf"><xsl:value-of select="@nodeName" /></a>
</p>
</xsl:template>
Get Media node from physical path
I have website search results that return the path to documents in the Media Library - how do I select the Media Library node for file?
/media/12345/file.pdf - how do I get the node in Umbraco?
Hi Gordon
Do you want the full path for the media nodes to be displayed on the search result? Or is it in Umbraco you're in doubt about how you select the media node? Or do you just need to know how to write out the path for the file with XSLT?
I'm not quite sure what it is that you need :-)
/Jan
As per the example I put in my post, the search result (from a Google Search Appliance as XML) is returning the physical path to the PDF. I want to find that PDF in the media library so that I can get the name given to it in the media library - rather than the physical file name.
Unfortunately, the number in the path which relates to the folder that contains the PDF is not the ID of the Media Library node. I cannot see any builtin Umbraco functions that will allow me to get the Media Library node and hence name.
I have investigated the database and found a way of locating the node ID, but it is not a solution I like.
Here's a topic that deals with this same issue.
Hi Gordon,
This is a crude way to do it, mainly because it forces you to collect all the Media items' XML into a variable, but once you've got that it's really a walk in the park (or on the 'X Path' so to speak :-)
If you've got all the PDFs in a single folder, for God's sake use that folder's ID as the MEDIA_NODE_ID.
Chriztian
I'm feeling a uComponents uQuery/XsltExtension coming on here! :-D
Man... I'm so crazy, we can already do this in uComponents! :-D
OK, so we've got these new Search methods, right? Try this...
This is all based on the assumption that you have uComponents AND a valid/stable/up-to-date Examine/Lucene index!
Cheers, Lee.
Have uComponents ... Examine/Lucene ... not sure!? If it's not there by default then no.
I tried the code anyway and it doesn't work :-(
Hi, forgive me if this is a silly question, but do you have the latest version of uComponents? - [2.1, i think]
the search extensions do not appear in earlier versions
Yes, I have the latest version but I just get "no results" back.
is working on a reply...