I am trying to index media content (such as PDFs) using Azure and to my surprise/frustration, this feature isn't supported: https://kb.sitecore.net/articles/830385
Is there a workaround that allows me to index file content on Azure?
Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. It only takes a minute to sign up.
Sign up to join this communityI am trying to index media content (such as PDFs) using Azure and to my surprise/frustration, this feature isn't supported: https://kb.sitecore.net/articles/830385
Is there a workaround that allows me to index file content on Azure?
The current implementation of Sitecore.ContentSearch
API depends on Adobe IFilter v9, which can't be installed in Azure App Service.
At the same time, Azure Search itself supports indexing different document formats (PDFs, DOCX/DOC, XLSX/XLS, PPTX/PPT, MSG etc.) when using Azure Blob Storage + Indexer for it: https://docs.microsoft.com/en-us/azure/search/search-howto-indexing-azure-blob-storage
Unfortunately, Sitecore doesn't support Azure Blob Storage for Media Library. It keeps blobs in Master
and Web
databases in SQL Server.
However, you can override the default MediaItemContentExtractor
, and replace dependency on Adobe iFilter COM component, with .NET port of Apache Tiki.
See the Sitecore.ContentSearch.Azure.DefaultIndexConfiguration.config
file
<fields hint="raw:AddComputedIndexField">
...
<field type="Sitecore.ContentSearch.ComputedFields.MediaItemContentExtractor,Sitecore.ContentSearch" fieldName="_content">
<mediaIndexing ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/mediaIndexing"/>
</field>
...
</fields>
You can create your own computed field that uses a PDF library to parse the file contents and store it in the index.
I followed this example: https://jeffdarchuk.com/2017/02/12/search-pdf-content-in-sitecore/
public class IndexPdfContent : IComputedIndexField
{
public object ComputeFieldValue(IIndexable indexable)
{
try
{
var sitecoreIndexable = indexable as SitecoreIndexableItem;
if (sitecoreIndexable == null) return null;
var pdfContent = new SitecorePdfParser(new MediaItem(sitecoreIndexable)).ExtractText().ToList();
if (pdfContent.Count == 0) return null;
return string.Join(" ", pdfContent);
}
catch (Exception e)
{
Log.Error("Unable to assemble PDF content for the search index ", e, this);
return null;
}
}
}
The main drawback is that this only includes PDF files. Sitecore on Lucene supports many different file types such as word documents etc, so that is something to consider.