protected IIndexableItem GetIndexableItem(Index indexConfig, ContentType contentTypeConfig, IContentBase content) { var itemToIndex = new IndexableItem(content.Id, content.Name, content.GetContentType().Alias); Dictionary <string, object> fieldGroups = new Dictionary <string, object>(); var propertiesToIndex = contentTypeConfig.IncludeAllProperties ? content.Properties.ToList() : content.Properties.Where(p => contentTypeConfig.Properties.Select(c => c.Alias).Contains(p.Alias)); foreach (var property in propertiesToIndex) { var indexField = new IndexFieldEvent { UmbracoProperty = property, Value = property.Value }; var propertyConfig = contentTypeConfig.Properties.FirstOrDefault(p => p.Alias == property.Alias); //Execute the property Index Strategy if one is configured if (propertyConfig != null && !string.IsNullOrEmpty(propertyConfig.IndexStrategy)) { var strategy = IndexStrategyResolver.GetPropertyIndexStrategy(propertyConfig.IndexStrategy); if (strategy != null) { strategy.Execute(indexField); } } //Add the value to a group field if one is configured if (propertyConfig != null && !string.IsNullOrEmpty(propertyConfig.Group)) { if (fieldGroups.ContainsKey(propertyConfig.Group)) { fieldGroups[propertyConfig.Group] += $" {indexField.Value}"; } else { fieldGroups.Add(propertyConfig.Group, indexField.Value); } } if (propertyConfig == null || (propertyConfig != null && !propertyConfig.ExcludeField)) { itemToIndex.AddOrUpdate(property.Alias, indexField.Value); } } foreach (var fieldGroup in fieldGroups) { itemToIndex.AddOrUpdate(fieldGroup.Key, fieldGroup.Value); } return(itemToIndex); }
public void Execute(IndexFieldEvent e) { var umbracoFileName = e.UmbracoProperty.Value != null?e.UmbracoProperty.Value.ToString() : string.Empty; var docPath = ConfigurationManager.AppSettings["Dexter:DocumentPath"]; var filePath = string.IsNullOrWhiteSpace(docPath) ? umbracoFileName : umbracoFileName.Replace("~/media", ConfigurationManager.AppSettings["Dexter:DocumentPath"]) .Replace("/media", ConfigurationManager.AppSettings["Dexter:DocumentPath"]); var text = string.Empty; switch (System.IO.Path.GetExtension(filePath)) { case ".pdf": text = new PdfToTextConverter().Convert(filePath); break; case ".doc": text = new DocToTextConverter().Convert(filePath); break; case ".xls": text = new XlsToTextConverter().Convert(filePath); break; case ".docx": text = new DocxToTextConverter().Convert(filePath); break; case ".xlsx": text = new XlsxToTextConverter().Convert(filePath); break; case ".pptx": text = new PptxToTextConverter().Convert(filePath); break; case ".ppt": text = System.IO.Path.GetFileName(filePath); break; case ".zip": text = new ZipToTextConverter().Convert(filePath); break; } e.Value = string.Join(" ", text.Split(new[] { ' ' }).Except(IGNORE)); }
public void Execute(IndexFieldEvent e) { var filePath = HttpContext.Current.Server.MapPath(e.UmbracoProperty.Value.ToString()); var bytes = File.ReadAllBytes(filePath); var text = ""; switch (System.IO.Path.GetExtension(filePath)) { case "pdf": text = ConvertPDFToText(bytes); break; } e.Value = string.Join(" ", text.Split(new[] { ' ' }).Except(IGNORE)); }
public void Execute(IndexFieldEvent indexField) { var text = indexField.Value as string; indexField.Value = string.Join(" ", text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); }