Esempio n. 1
0
        private IEnumerable <SearchableDocument> GetSearchableDocument(IPublishedContent content)
        {
            var fileName  = Path.GetFileName(content.Url);
            var extension = Path.GetExtension(fileName)?.Trim('.');

            bool isFileExtensionAllowedForIndex = _settings.IndexingDocumentTypesKey.Contains(extension, StringComparison.OrdinalIgnoreCase);


            if (!content.Url.IsNullOrEmpty())
            {
                var physicalPath = HostingEnvironment.MapPath(content.Url);

                if (!File.Exists(physicalPath))
                {
                    _exceptionLogger.Log(new FileNotFoundException($"Could not find file \"{physicalPath}\""));
                    return(Enumerable.Empty <SearchableDocument>());
                }
                var base64File = isFileExtensionAllowedForIndex ? Convert.ToBase64String(File.ReadAllBytes(physicalPath)) : string.Empty;
                var result     = new SearchableDocument
                {
                    Id    = content.Id,
                    Title = fileName,
                    Url   = content.Url,
                    Data  = base64File,
                    Type  = SearchableTypeEnum.Document.ToInt()
                };
                return(result.ToEnumerable());
            }
            return(Enumerable.Empty <SearchableDocument>());
        }
 public void Index(SearchableDocument content)
 {
     _elasticSearchRepository.EnsureMappingExist();
     _elasticSearchRepository.Save(content);
 }