diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index 104c451273..485512cefb 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -81,6 +81,26 @@ namespace Umbraco.Web.Editors return ExamineSearch(query, type, searchFrom); } + /// + /// Searches media and returns a list of ContentItemBasic based on the IMedia + /// + /// + /// + /// + [HttpGet] + public IEnumerable> SearchMedia(string query, string searchFrom = null) + { + if (string.IsNullOrEmpty(query)) + return Enumerable.Empty>(); + + // limiting the examine results to 50 to avoid killing the GetByIds lookup + var searchResult = ExamineSearch(query, UmbracoEntityTypes.Media, searchFrom).Take(50); + var mediaItems = Services.MediaService.GetByIds(searchResult.Select(x => Convert.ToInt32(x.Id))) + .Select(Mapper.Map>); + + return mediaItems; + } + /// /// Searches for all content that the user is allowed to see (based on their allowed sections) ///