Unified search and culture specific MediaData
I was creating a search page for a customer using EPiServer Find. As they have plenty of page types, I decided to use unified search. However, they also have a lot of documents (PDFs) that should also be searchable .No problem, unified search takes care of that out of the box. But this site also had several languages, and since MediaData in EPiServer 7.5 is not localizable, I had to write some code as Find has no way of knowing which language the different files should be part of. Here is what I did:
First, a string property should be added to a MediaData base class, which will store the language ID.
To make it more editor friendly, the SelectOne attribute could be used on the property(Check out Linus’s blog post for more information regarding the SelectOne attribute). In this case it uses a selection factory that returns all available languages on the site:
Then, an extension method that will use the language property and do the appropriate filtering. The extension method should only filter non-localizable items, so that it will not affect pages.
And finally, use the extension method in the Find query
That’s it! Culture specific file search is now working. Setting the languages property on the files will be required though.
Related super quick tip:In this case I also saw the need to remove image files from the result