6

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?

| improve this question | | | | |
6

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>
| improve this answer | | | | |
  • I've ran into an issue with this where it seems it only works with small PDF files. When using a larger files (such as 1MB) the item doesn't get indexed. The computed field gets hit, and returns the content, but the item just doesn't get updated in the index & there is nothing in the logs to suggest an error. The only limitation I can see documented on Azure Search is that documents cannot be greater than 16MB - no field level restrictions. So this doesn't seem like a viable solution at the moment. – David Masters Jan 31 '18 at 14:31
4

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.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.