November Happy Hour will be moved to Thursday December 5th.

Index properties but not file?

Vote:
 

Hi,
we have files that are quite big, and we see no reason to index them in find. But we would like to index the properties on the filetype. Is there a way to index the properties of the file but not the file it self? Or is this handled automagically?

/Erik

#122800
Jun 15, 2015 8:48
Vote:
 

Hi, have you tried setting PdfFile.BinaryData to null?

Here is some indexing conventions 

ContentIndexer.Instance.Conventions.ForInstancesOf<PdfFile>().ShouldIndex(x => x.FileSizeInKb < 20000);
SearchClient.Instance.Conventions.ForInstancesOf<PdfFile>().IncludeField(x => x.SetCustomProperties());

We have solved the matter by setting an limit aprox 20 mb

Let me know it that worked

/Daniel

#122804
Jun 15, 2015 11:49
Vote:
 

Hi Daniel, we have a convention that allows files up to 30MB, but we need to index properties of a 500MB file.. How would you null the BinaryData just for some specific files when indexing?

#122912
Jun 17, 2015 15:34
Vote:
 

Hi,

The binary data of a IContentMedia item is passed to the index using the SearchAttachment extension. In order to skip passing the data (while having all other properties passed) you have to override the default SearchAttachment extension and set it to null if the file exceeds your limit:

First create a SearchAttachment() extension for they type (it has to be named SearchAttachment for UnifiedSearch to work properly):

public static Attachment SearchAttachment(this $FileType$ mediaData)

        {

            if (ContentIndexer.Instance.Conventions.ShouldIndexAttachmentConvention.ShouldIndexAttachment(mediaData).HasValue &&

                ContentIndexer.Instance.Conventions.ShouldIndexAttachmentConvention.ShouldIndexAttachment(mediaData).Value)

            {

                if (mediaData.BinaryData.IsNotNull())

                {

                    using (var stream = mediaData.BinaryData.OpenRead())

                    {

                        if (stream.Length < $FileSize$)

                        {

                            return new Attachment(() => mediaData.BinaryData.OpenRead());

                        }

                    }

                }

            }

            return null;

        }

and add it to your conventions by overriding the default convention on IContentMedia:

client.Conventions.ForInstancesOf<$FileType$>()

                .ExcludeField(x => ((IContentMedia) x).SearchAttachment())

                .IncludeField(x => x.SearchAttachment());

/Henrik

#123067
Jun 24, 2015 11:33
Vote:
 

Thank you Henrik for the clarification. I've implemented this and hopefully have a happier customer now. :)

#123117
Jun 25, 2015 10:41
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.